I want to parse XML in bash and xpath could do it.
(To get “Description” element with subelement “em:minVersion=2.1”) query like this works well:
xpath install.rdf /RDF/Description/em:targetApplication/Description[em:minVersion=2.1]
But this won’t work:
xpath install.rdf /RDF/Description/em:targetApplication/Description[em:id={ec8030f7-c20a-464f-9b0e-13a3a9e97384}]
Output like this:
Query:
/RDF/Description/em:targetApplication/Description[em:id={{ec8030...
.......................................................^^^
Invalid query somewhere around here (I think)
I think it’s because curly brackets “{}” need escaping, so I tried ‘{{..}}’, ‘{…}’… none of them works.
I’m not familiar with xpath or perl at all…
Try
This doesn’t actually have anything to do with Perl, other than the fact that the
xpathutility is written in it. It’s all aboutbashand XPath.To prevent
bashfrom looking at it, put the whole query in single quotes.In XPath, strings must be quoted (with either single or double quotes). It’s generally easiest to use double quotes inside the XPath expression, and then put single quotes around it for
bash.Since you’re searching for
the condition you want is
You’re getting away with
em:minVersion=2.1because 2.1 looks like a number, so XPath does a numeric comparison. But that won’t work with arbitrary strings.