XMLStarlet: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(31 intermediate revisions by the same user not shown)
Line 4: Line 4:
=Internal=
=Internal=
* [[XPath#Tooling|XPath]]
* [[XPath#Tooling|XPath]]
* [[XSLT]]
=Overview=
=Overview=
XMLStartlet ships with one executable called <code>xml</code>, which can be used as the short form of the <code>xmlstarlet</code> command.
XMLStartlet ships with one executable called <code>xml</code>, which can be used as the short form of the <code>xmlstarlet</code> command.
=XPath Syntax=
{{Internal|XPath#Syntax|XPath Syntax}}


=Usage=
=Usage=


  xml [[[#General_Options|options]]] <[[#Commands|command]]> [command options]
  xml &#91;[[#General_Options|options]]] <[[#Commands|command]]> [command options]
 
=<tt>sel</tt> Command=
Select (query) an XML file using XPath. It can also generate an [[XSLT#Overview|XSLT]] document. Internally, when <code>sel</code> command is used, the tool converts internally the commands into an XSLT to perform the query.
xml sel --help
==<tt>sel -t</tt>==
Create an [[XSLT#XSLT_Template|XSLT template]] using the provided options.
xml sel -t <template options> <xml-file-name>
 
Return codes:
* If the path does not match anything, the command return an empty stdout/stderr and an "1" exit code.
* If the file does not exist, the command returns "3" as exit code and a message along the lines of 'failed to load external entity "<file-name>"'.
===Template Options===
===<span id='-c'></span><tt>-t -c</tt>===
Print a copy of XPath expression.  Return the element (elements) that match the provided XPath expression, including the XML tags.
xml sel -t -c "<xpath-expression>" <xml-file-name>
 
xml sel -t -c "//book[@category='linux']" <xml-file-name>
The example is taken from [[XPath#Example|XPath &#124; Example]].


==General Options==
===<span id='-v'></span><tt>-t -v</tt>===
==Commands==
Print the value of the XPath expression. The XML tags are omitted from the output.
===<tt>sel</tt>===
xml sel -t -v "<xpath-expression>" <xml-file-name>


=Options=
xml sel -t -v "//book[@category='linux']" <xml-file-name>
==<tt>-t</tt>==
The example is taken from [[XPath#Example|XPath &#124; Example]].
==<tt>-c</tt>==
==<tt>-v</tt>==


=XPath Syntax=
=<tt>ed</tt> Command=
{{Internal|XPath#Syntax|XPath Syntax}}
Edit an XML file.
=<tt>tr</tt> Command=
Transform an XML file using [[XSLT]].
=General Options=

Latest revision as of 05:10, 1 July 2021

External

Internal

Overview

XMLStartlet ships with one executable called xml, which can be used as the short form of the xmlstarlet command.

XPath Syntax

XPath Syntax

Usage

xml [options] <command> [command options]

sel Command

Select (query) an XML file using XPath. It can also generate an XSLT document. Internally, when sel command is used, the tool converts internally the commands into an XSLT to perform the query.

xml sel --help

sel -t

Create an XSLT template using the provided options.

xml sel -t <template options> <xml-file-name>

Return codes:

  • If the path does not match anything, the command return an empty stdout/stderr and an "1" exit code.
  • If the file does not exist, the command returns "3" as exit code and a message along the lines of 'failed to load external entity "<file-name>"'.

Template Options

-t -c

Print a copy of XPath expression. Return the element (elements) that match the provided XPath expression, including the XML tags.

xml sel -t -c "<xpath-expression>" <xml-file-name>
xml sel -t -c "//book[@category='linux']" <xml-file-name>

The example is taken from XPath | Example.

-t -v

Print the value of the XPath expression. The XML tags are omitted from the output.

xml sel -t -v "<xpath-expression>" <xml-file-name>
xml sel -t -v "//book[@category='linux']" <xml-file-name>

The example is taken from XPath | Example.

ed Command

Edit an XML file.

tr Command

Transform an XML file using XSLT.

General Options