Last month, I figured out how to query with namespace using xmllint, but there is a more easier way using different program, xmlstarlet.

For exact same results using xmlstarlet:


xmlstarlet sel -N a="http://purl.org/rss/1.0/" -t -m '//a:item[1]/a:description' -v 'text()' test.xml

Using xmllint, tricky and ugly…:


echo -e 'setns a=http://purl.org/rss/1.0/\ncat //a:item[1]/a:description/text()' | xmllint --shell test.xml

The template -t option in xmlstarlet can be very helpful if you don’t want to use XSLT for some simple output. You can compose the template entirely in command-line fashion.