Spec-Zone.ru › Nushell

query xml for filters

Execute XPath 1.0 query on XML input

Signature

> query xml {flags} (query)

Flags

  • --namespaces, -n {record}: Map of prefixes to namespace URIs.
  • --output-string-value: Include string_value in the nodeset output. On by default.
  • --output-type: Include type in the nodeset output. Off by default.
  • --output-names: Include local_name, prefixed_name, and namespace 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.

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/query_xml.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API