Revision [1072]

This is an old revision of CommandXpath made by DavidLee on 2009-11-29 10:35:09.

 

Command xpath


Name

xpath evaluate an XPATH expression and print the result

Synopsis

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


Options

-f xpath-file
-file xpath-file
read xpath expression from file
-i context
-input context
use context as the source xml document, otherwise stdin if context is an XML expression which is an item then use it directly as the context item.
-c context
-context context
Use context as a literal context
-cf file
-context-file file
Use file as the name of an XML file for the context, or "-" for 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.




-i is depreciated. It is a convenience option that does the following
-c or -cf are suggested which explicitly indicate if to use the expression literally or as a filename



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