Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xmllint unknown option '--xpath'

Tags:

xpath

xmllint

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?

like image 984
Neal Pisenti Avatar asked Aug 15 '12 19:08

Neal Pisenti


4 Answers

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()'
like image 126
Alexey Avatar answered Oct 20 '22 17:10

Alexey


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
like image 38
trompa Avatar answered Oct 20 '22 15:10

trompa


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.

like image 30
Neal Pisenti Avatar answered Oct 20 '22 15:10

Neal Pisenti


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.

like image 1
jhabbott Avatar answered Oct 20 '22 16:10

jhabbott