Reputation: 12323
Given xml
<parent>
<child>test1</child>
<child>test2</child>
</parent>
Using xmllint I can get the childs with:
| xmllint --format --xpath '//parent/child/text()' -
This gives the result
test1test2
Is there an easy way to return it with a separator between them, e.g. test1-test2
or a space, like test1 test2
.
The goal is to use the found matches in a pipeline and loop over them, but because everything is merged together without a separator it is not working.
EDIT using rhel7
Upvotes: 1
Views: 58
Reputation: 12662
xmllint --shell
can be used as follows
printf "%s\n" 'cat //parent/child/text()' 'bye' | xmllint --shell <(cat tmp2.xml)
/ > cat //parent/child/text()
-------
test1
-------
test2
/ > bye
Cleaning the ouput
printf "%s\n" 'cat //parent/child/text()' 'bye' | xmllint --shell <(cat tmp2.xml) | grep -Ev '^(\/ > | ----)'
test1
test2
Upvotes: 0