Revision [1060]

This is an old revision of CommandXpath made by DavidLee on 2009-11-27 03:51:58.

 

Command xpath


Name

xpath evaluate an XPATH expression and print the result

Synopsis

xpath [ serialization options ] [options] [xpath-expr]


Options

if input is an XML expression then use it directly (dont treat as filename).
-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

If the result (or any node of the result if a sequence) is an Attribute the it is converted to a string.



Example

xls | xpath '//file[1]/@name/string()'

Result
.classpath


Simplified example, you don't need to use /string()
xls | xpath '//file[1]/@name'

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 1


Commands
CategoryCommands
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki