Revision [947]
This is an old revision of CommandXpath made by DavidLee on 2009-11-24 18:34:21.
Command xpath
Name
xpath evaluate an XPATH expression and print the resultSynopsis
xpath [ serialization options ] [options] [xpath-expr]Options
-f xpath-file -file xpath-file | read xpath expression from file |
-input input -i input | use input as the source xml document, otherwise stdin |
-n | do not use a source context |
-q xpath-expr -query xpath-expr | xpath expression |
-v | Read remaining pairs of arguments as name/value pairs to assign as xpath variables |
-nons | Do not import global namespace declarations from the shell environment |
-ns prefix=uri | Add a predeclared namespace delcaration |
-s -string | Convert the result to a string if it is an attribute or element |
-b -bool | Do not print anything. Treat the result as a boolean and exit with 0 if the value is true otherwise 1 |
-e -exists | Execute xpath but do not print anything. The exit status is 0 if there was any selected values otherwise 1 |
Supports the standard [ serialization options ]
Note that the "-q" is optional. It is only required if you need to specify both -n and -v
Examples
xpath-n -q expr -v variable some-value
Example
xls | xpath '//file[1]/@name/string()'
Result
.classpath
Namespace example using a renamed prefix for a namespace
echo "<x:a xmlns:x='foo' />" | xpath -nons -ns y=foo /y:a
Result
<x:a xmlns:x="foo"/>
Return Value
Returns 0 if the the xpath expression executed successfully and a non-empty result is returned. otherwise 1Commands
CategoryCommands