2021-08-16 13:23:55 +01:00
|
|
|
# xml select
|
2021-08-14 23:17:52 +01:00
|
|
|
|
2021-08-21 04:20:02 +01:00
|
|
|
> Select from XML documents using XPATHs.
|
|
|
|
> Tip: use `xml elements` to display the XPATHs of an XML document.
|
|
|
|
> More information: <http://xmlstar.sourceforge.net/docs.php>.
|
2021-08-14 23:17:52 +01:00
|
|
|
|
2021-08-24 19:57:47 +01:00
|
|
|
- Select all elements matching "XPATH1" and print the value of their sub-element "XPATH2":
|
2021-08-15 19:38:24 +01:00
|
|
|
|
2021-08-24 02:20:17 +01:00
|
|
|
`xml select --template --match "{{XPATH1}}" --value-of "{{XPATH2}}" {{path/to/input.xml|URI}}`
|
2021-08-15 19:38:24 +01:00
|
|
|
|
2023-06-14 16:32:31 +01:00
|
|
|
- Match "XPATH1" and print the value of "XPATH2" as text with new-lines:
|
2021-08-15 19:38:24 +01:00
|
|
|
|
2021-08-24 02:20:17 +01:00
|
|
|
`xml select --text --template --match "{{XPATH1}}" --value-of "{{XPATH2}}" --nl {{path/to/input.xml|URI}}`
|
2021-08-15 19:38:24 +01:00
|
|
|
|
2021-08-21 04:20:02 +01:00
|
|
|
- Count the elements of "XPATH1":
|
2021-08-15 19:38:24 +01:00
|
|
|
|
2021-08-21 04:20:02 +01:00
|
|
|
`xml select --template --value-of "count({{XPATH1}})" {{path/to/input.xml|URI}}`
|
2021-08-15 19:38:24 +01:00
|
|
|
|
2021-08-24 02:20:17 +01:00
|
|
|
- Count all nodes in one or more XML documents:
|
2021-08-15 19:38:24 +01:00
|
|
|
|
2021-08-21 04:20:02 +01:00
|
|
|
`xml select --text --template --inp-name --output " " --value-of "count(node())" --nl {{path/to/input1.xml|URI}} {{path/to/input2.xml|URI}}`
|
2021-08-15 19:38:24 +01:00
|
|
|
|
2021-08-16 13:23:55 +01:00
|
|
|
- Display help for the `select` subcommand:
|
2021-08-14 23:17:52 +01:00
|
|
|
|
|
|
|
`xml select --help`
|