Revision [1890]

Last edited on 2013-03-08 16:59:44 by DavidLee
Additions:
Namespace example using xmlsh [[Namespaces]] support
declare namespace y=foo
echo "<x:a xmlns:x='foo' />" | xpath /y:a


Revision [1232]

Edited on 2010-02-15 10:21:52 by DavidLee
Additions:
||-f,-file xpath-file|| read xpath expression from file||
||-i,-input context||(depreciated) 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||Use context as a literal context||
||-cf,-context-file file||Use file as the name of an XML file for the context, or "-" for stdin||
||-q,-query xpath-expr||xpath expression||
||-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||
Deletions:
||-f xpath-file
-file xpath-file|| read xpath expression from file||
||-i context
-input context||(depreciated) 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||
||-q xpath-expr
-query xpath-expr|| xpath expression||
||-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||


Revision [1072]

Edited on 2009-11-29 10:35:09 by DavidLee

No Differences

Revision [1071]

Edited on 2009-11-29 10:34:57 by DavidLee
Additions:
||-i context
-input context||(depreciated) 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||
-i is depreciated. It is a convenience option that does the following
- If context is an atomic value then treat as a filename to be loaded as the context item
- Otherwise treat as the literal context for the context item
-c or -cf are suggested which explicitly indicate if to use the expression literally or as a filename
Deletions:
||-input input
-i input||use input as the source xml document, otherwise stdin||
if input is an XML expression then use it directly (dont treat as filename).||


Revision [1060]

Edited on 2009-11-27 03:51:58 by DavidLee
Additions:

If the result (or any node of the result if a sequence) is an Attribute the it is converted to a string.
Simplified example, you don't need to use /string()
xls | xpath '//file[1]/@name'


Revision [947]

Edited on 2009-11-24 18:34:21 by DavidLee
Additions:
[[Commands]]


Revision [946]

Edited on 2009-11-24 18:34:12 by DavidLee
Additions:
||-e
-exists||Execute xpath but do not print anything. The exit status is 0 if there was any selected values otherwise 1||
Deletions:
||-e||Execute xpath but do not print anything. The exit status is 0 if there was any selected values otherwise 1||


Revision [945]

Edited on 2009-11-24 18:33:43 by DavidLee
Additions:
-i input||use input as the source xml document, otherwise stdin||
if input is an XML expression then use it directly (dont treat as filename).||
Deletions:
-i input|| use input as the source xml document, otherwise stdin||
if input is an XML expression then use it directly (dont treat as filename).||


Revision [944]

Edited on 2009-11-24 18:33:17 by DavidLee
Additions:
xpath [ [[SerializationOptions 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||
if input is an XML expression then use it directly (dont treat as filename).||
||-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||Execute xpath but do not print anything. The exit status is 0 if there was any selected values otherwise 1||
Supports the standard [ [[SerializationOptions serialization options]] ]
xls | xpath '//file[1]/@name/string()'
Result
.classpath
echo "<x:a xmlns:x='foo' />" | xpath -nons -ns y=foo /y:a
Result
Deletions:
xpath [-f xpath-file] [-i input-file] [-n] [-nons] [-ns prefix=uri [-ns ..]] [-q] xpath-expr [-method method] [-v name value [name value ...]]
====Description====
-f xpath-file read xpath expression from file
-i input use input as the source xml document, otherwise stdin
if input is an XML expression then use it directly (dont treat as filename).
-n do not use a source context
[-q] 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
-method output-method Changes the default output method for serialzation. Must be one of (xml,html,xhtml,text)
$ xls | xpath '//file[1]/@name'
name=".classpath"
$ echo "<x:a xmlns:x='foo' />" | xpath -nons -ns y=foo /y:a


Revision [872]

Edited on 2009-11-23 06:54:59 by DavidLee
Additions:
xpath [-f xpath-file] [-i input-file] [-n] [-nons] [-ns prefix=uri [-ns ..]] [-q] xpath-expr [-method method] [-v name value [name value ...]]
-method output-method Changes the default output method for serialzation. Must be one of (xml,html,xhtml,text)
Deletions:
xpath [-f xpath-file] [-i input-file] [-n] [-nons] [-ns prefix=uri [-ns ..]] [-q] xpath-expr [-v name value [name value ...]]


Revision [790]

Edited on 2009-09-16 08:02:36 by DavidLee
Deletions:
[[CommandsInternal]]


Revision [355]

Edited on 2009-01-03 07:11:54 by DavidLee
Additions:
[[CommandsInternal]]


Revision [305]

Edited on 2008-11-21 10:21:57 by DavidLee
Additions:
Namespace example using a renamed prefix for a namespace
$ echo "<x:a xmlns:x='foo' />" | xpath -nons -ns y=foo /y:a
<x:a xmlns:x="foo"/>


Revision [302]

Edited on 2008-11-21 10:19:59 by DavidLee
Additions:
xpath [-f xpath-file] [-i input-file] [-n] [-nons] [-ns prefix=uri [-ns ..]] [-q] xpath-expr [-v name value [name value ...]]
-nons Do not import global namespace declarations from the shell environment
-ns prefix=uri Add a predeclared namespace delcaration
Deletions:
xpath [-f xpath-file] [-i input-file] [-n] [-q] xpath-expr [-v name value [name value ...]]


Revision [282]

Edited on 2008-10-25 11:44:41 by DavidLee
Additions:
xpath [-f xpath-file] [-i input-file] [-n] [-q] xpath-expr [-v name value [name value ...]]
if input is an XML expression then use it directly (dont treat as filename).
-n do not use a source context
[-q] xpath-expr xpath expression
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
Returns 0 if the the xpath expression executed successfully and a non-empty result is returned. otherwise 1
Deletions:
xpath [-f xpath-file] [-i input-file] [-n] xpath-expr [-v name value [name value ...]]
if input is an XML expression then use it directly (dont treat as filename).
-n do not use a source context
xpath-expr xpath expression
Returns 0 if the the xpath expression executed successfully. otherwise 1


Revision [239]

Edited on 2008-07-04 09:13:42 by DavidLee
Additions:
xpath [-f xpath-file] [-i input-file] [-n] xpath-expr [-v name value [name value ...]]
-i input use input as the source xml document, otherwise stdin
if input is an XML expression then use it directly (dont treat as filename).
-v Read remaining pairs of arguments as name/value pairs to assign as xpath variables
Deletions:
xpath [-f xpath-file] [-i input-file] [-n] xpath-expr
-i input-file use input-file as the source xml document, otherwise stdin


Revision [123]

Edited on 2008-04-25 18:49:58 by DavidLee
Additions:
Returns 0 if the the xpath expression executed successfully. otherwise 1
----
[[CategoryCommands]]
Deletions:
Returns 0 if the the xpath expression executed successfully. otherwise 1


Revision [116]

Edited on 2008-04-25 18:18:40 by DavidLee
Additions:
xpath-expr xpath expression
Returns 0 if the the xpath expression executed successfully. otherwise 1
Deletions:
Returns 0 if the the xpath expression executed successfully. otherwise 1


Revision [115]

Edited on 2008-04-25 18:17:46 by DavidLee
Additions:
xpath [-f xpath-file] [-i input-file] [-n] xpath-expr
-f xpath-file read xpath expression from file
-i input-file use input-file as the source xml document, otherwise stdin
-n do not use a source context
====Example====
%%(shell)
$ xls | xpath '//file[1]/@name'
name=".classpath"
%%
Deletions:
xpath [-f file] [-i] [-n] xpath-expr


Revision [114]

The oldest known version of this page was created on 2008-04-25 17:59:51 by DavidLee
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki