Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

query xml for filters

Execute XPath 1.0 query on XML input

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: 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:

inputoutput
stringany

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.