xmllint is a helpful tool for anazing xml files. one common usage is its xpath query, which can extract useful information from a xml file.

for example, let this xml file be our input input.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
<point x="10" y="20"/>
<point x="11" y="21"/>
<point x="12" y="22"/>
<point x="13" y="23"/>
<point x="14" y="24"/>
</config>


we can extract all x coordinates using xpath:

xmllint --xpath "//point/@x" input.xml


output:

 x="10" x="11" x="12" x="13" x="14"


the result is correct, but ugly. this example has only 5 results, but in other use cases the number can be quite large and it won’t be obvious how many results there are. plus, many text-based tools work well with lines. if the result needs further processing, it should be separated by newlines, instead of spaces.

## hack

there is a hack to force each output displayed in a new line:

xmllint --shell <<< "cat //point/@x" input.xml


output:

/ >  -------
x="10"
-------
x="11"
-------
x="12"
-------
x="13"
-------
x="14"
/ >


while the result does spread across separate lines, they are separated by ugly markers. these markers would make downstream work more difficult.

## solution

so let me give the correct solution. we should separate result nodes by a user-defined separator. this requires a bit research into a 3000-line-ish text. but here is a patch that works:

with this patch, we can write a command like this:

xmllint --xpath "//point/@x" --xpath-node-separator "\n" input.xml


output:

 x="10"
x="11"
x="12"
x="13"
x="14"


### update (20180922)

this patch has been deprecated. for most recent changes, please visit the git repo for the patched program.