Given the file:
/// @file test.xml
<xml-fragment>
<string name="foo" value="bar"/>
</xml-fragment>
the path xml-fragment/string
and the attribute&value name="foo"
to filter on, and the attribute value
to query on, how should I get "bar"
?
Using xmlstarlet
, I have this:
xmlstarlet sel -t -m '/xml-fragment/string[attribute::name="foo"]' \
-v 'attribute::bar' test.xml
which appears to work, but I'm wondering if there is a better way?
I don't even require using xmlstarlet
; I previously tried xmllint
, xsltproc
, and xpath
, but couldn't get those to work.