]$ xmllint --version
xmllint: using libxml version 20626
My xml file looks something like this:
<projects>
<architecture name="ARCH1">
<project label="StringA1" type="StringB1" state="StringC1"/>
......
</architecture>
<architecture name="ARCH2">
<project label="StringA2" type="StringB2" state="StringC2"/>
......
</architecture>
</projects>
For example, I would like to obtain the value StringB2 given the condition name==ARCH2 and state==StringC2. Is it possible using xmllint command line options, if yes, how ? Some examples will be beneficial.
I can extract these using sed or awk but that may not be a good solution.
Try the following
xmllint --xpath 'string(///project[../@name="ARCH1" and @state="StringC1"]/@type)' data.xml
Version:
$ xmllint --version
xmllint: using libxml version 20900
compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib Lzma
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With