Get xmllint to output xpath results \n-separated, for attribute selector Get xmllint to output xpath results \n-separated, for attribute selector xml xml

Get xmllint to output xpath results \n-separated, for attribute selector


You can try:

$ xmllint --shell inputfile <<< 'cat /config/*/@*'

You might need to grep the output, though, so as to filter the undesired lines.


If it's an option, try using xmlstarlet instead:

xmlstarlet sel -t -v "/config/*/@*" example.xml


The question is old but as I came to this post searching a solution to the same problem, here is my solution

On linux add sed substitution to split output:

$ xmllint example.xml --xpath "/config/*/@*" | sed "s| key|\nkey|g"

of course the substitution expression depends on your xml structure and your xpath query.

And you can even add line numbers on each line if you add nl

$ xmllint example.xml --xpath "/config/*/@*" | sed "s| key|\nkey|g" | nl

Which gives

   1 key1="value1 "   2 key2=" value2"   3 key3="value3"   4 key4=" value4 "