query xml
for filters
This command requires a plugin
The query xml
command resides in the query
plugin. To use this command, you must install and register nu_plugin_query
. See the Plugins chapter in the book for more information.
Signature
> query xml {flags} (query)
Flags
--namespaces, -n {record}
: map of prefixes to namespace URIs--output-string-value
: Includestring_value
in the nodeset output. On by default.--output-type
: Includetype
in the nodeset output. Off by default.--output-names
: Includelocal_name
,prefixed_name
, andnamespace
in the nodeset output. Off by default.
Parameters
query
: xpath query
Input/output types:
input | output |
---|---|
string | any |
Examples
Query namespaces on the root element of an SVG file
> http get --raw https://www.w3.org/TR/SVG/images/conform/smiley.svg
| query xml '/svg:svg/namespace::*' --output-string-value --output-names --output-type --namespaces {svg: "http://www.w3.org/2000/svg"}
Query the language of Nushell blog (xml:
prefix is always available)
> http get --raw https://www.nushell.sh/atom.xml
| query xml 'string(/*/@xml:lang)'
Query all XLink targets in SVG document
> http get --raw https://www.w3.org/TR/SVG/images/conform/smiley.svg
| query xml '//*/@xlink:href' --namespaces {xlink: "http://www.w3.org/1999/xlink"}
Get recent Nushell news
> http get --raw https://www.nushell.sh/atom.xml
| query xml '//atom:entry/atom:title|//atom:entry/atom:link/@href' --namespaces {atom: "http://www.w3.org/2005/Atom"}
| window 2 --stride 2
| each { {title: $in.0.string_value, link: $in.1.string_value} }
Notes
Scalar results (Number, String, Boolean) are returned as nu scalars. Output of the nodeset results depends on the flags used: - No flags: returns a table with string_value
column. - You have to specify --output-string-value
to include string_value
in the output when using any other --output-*
flags. - --output-type
includes type
column with node type. - --output-names
includes local_name
, prefixed_name
, and namespace
columns.