xmllint unknown option '--xpath'
Asked Answered
I

4

23

I've seen this syntax several places (eg, here):

xmllint --xpath '/plist/array/string/text()' tmp.xml, used to query a particular XML node using an xpath selector. However, I'm getting the error Unknown option --xpath when I try to execute this on my machine (mac os x snow leopard).

Looking more closely at the man page for xmllint, I don't see the --xpath option documented...

Am I just totally missing something here?

Isacco answered 15/8, 2012 at 19:27 Comment(2)
I also can't find --xpath option (on my Linux box) but in my case xmllint knows about this option: xmllint | grep xpath return --xpath expr: evaluate the XPath expression, inply --noout. Show to us output of xmllint --version command. Maybe this program should be compiled with/or without XPath support?..Henceforth
See @steve.sims answer to this question for using older versions of xmllint that do not support the --xpath argument.Exponent
I
8
xmllint --shell tmp.xml <<<'xpath /plist/array/string/text()'

If you need to make xmllint to read stdin:

cat /tmp/tmp.xml | xmllint --shell <(cat) <<<'xpath /plist/array/string/text()'
Ithaca answered 5/7, 2016 at 9:6 Comment(2)
Alexey, I used the exact same command and I am getting - 'Missing name for redirect.'. Can you please helpCalvaria
I do not know exactly but sometimes or on the different shell version construction <(cat) did not work. Try to use file instead or - as file.Ithaca
M
6

For some people updating is not an option. You have to work with the given version, that is installed by some other team and you go with it.

You can try through --shell:

xmllint --shell tmp.xml << EOF
'/plist/array/string/text()'
EOF
Macron answered 4/5, 2015 at 14:30 Comment(1)
Thankyou @Trompa, this demonstrated that it is possible with an old xmllint; I used the xmllint --shell command 'cat' to extract a tomcat HTTP listener port in 1-line thus: echo "cat //Connector[@protocol='org.apache.coyote.http11.Http11NioProtocol']/@port" | xmllint --shell /apache-tomcat/conf/server.xml | awk -F\" '/=/ { print $2; }'Snowfield
I
5

Ah, yep, must've been an issue with an outdated version of libxml2.

Updating libxml2 (to v2.7.8) via macports seems to have fixed the problem.

Isacco answered 15/8, 2012 at 19:41 Comment(0)
K
1

If you want to manipulate plist files from the command line on a Mac, use PlistBuddy.

For example, you can do this kind of thing in a shell script:

BUNDLE_ID=`/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' Info.plist`
echo $BUNDLE_ID

It's very powerful, you can add/delete items in arrays and dictionaries, look up keyed or indexed values, copy/merge/import other files, etc. See /usr/libexec/PlistBuddy -h for full info.

Kelda answered 9/1, 2013 at 12:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.