unix - *NIX CLI: Filter, Query XML Attribute and Display -
given file:
/// @file test.xml <xml-fragment> <string name="foo" value="bar"/> </xml-fragment> the path xml-fragment/string , attribute&value name="foo" filter on, , attribute value query on, how should "bar"?
using xmlstarlet, have this:
xmlstarlet sel -t -m '/xml-fragment/string[attribute::name="foo"]' \ -v 'attribute::bar' test.xml which appears work, i'm wondering if there better way?
i don't require using xmlstarlet; tried xmllint, xsltproc, , xpath, couldn't work.
i'm not sure if "better", use -v entire xpath. use @ abbreviated syntax.
example (tested in windows; quotes might need changed)
xmlstarlet sel -t -v "/xml-fragment/string[@name='foo']/@value" test.xml any of other tools listed should work well. if you're getting value, xsltproc might overkill. long you're not using regex, should ok.
Comments
Post a Comment