2017-07-14 09:36:12 +01:00
|
|
|
# xmllint
|
|
|
|
|
2017-08-25 10:09:36 +01:00
|
|
|
> XML parser and linter that supports XPath, a syntax for navigating XML trees.
|
2021-10-04 13:32:27 +01:00
|
|
|
> More information: <https://manned.org/xmllint>.
|
2017-07-14 09:36:12 +01:00
|
|
|
|
2017-08-25 10:09:36 +01:00
|
|
|
- Return all nodes (tags) named "foo":
|
2017-07-14 09:36:12 +01:00
|
|
|
|
|
|
|
`xmllint --xpath "//{{foo}}" {{source_file.xml}}`
|
|
|
|
|
2017-08-25 10:09:36 +01:00
|
|
|
- Return the contents of the first node named "foo" as a string:
|
2017-07-14 09:36:12 +01:00
|
|
|
|
2017-08-25 10:09:36 +01:00
|
|
|
`xmllint --xpath "string(//{{foo}})" {{source_file.xml}}`
|
2017-07-14 09:36:12 +01:00
|
|
|
|
2021-08-15 18:59:09 +01:00
|
|
|
- Return the href attribute of the second anchor element in an HTML file:
|
2017-07-14 09:36:12 +01:00
|
|
|
|
2017-08-25 10:09:36 +01:00
|
|
|
`xmllint --html --xpath "string(//a[2]/@href)" webpage.xhtml`
|
2017-07-14 09:36:12 +01:00
|
|
|
|
2017-08-25 10:09:36 +01:00
|
|
|
- Return human-readable (indented) XML from file:
|
2017-07-14 09:36:12 +01:00
|
|
|
|
|
|
|
`xmllint --format {{source_file.xml}}`
|
|
|
|
|
2021-08-15 18:59:09 +01:00
|
|
|
- Check that an XML file meets the requirements of its DOCTYPE declaration:
|
2017-07-14 09:36:12 +01:00
|
|
|
|
|
|
|
`xmllint --valid {{source_file.xml}}`
|
|
|
|
|
|
|
|
- Validate XML against DTD schema hosted online:
|
|
|
|
|
|
|
|
`xmllint --dtdvalid {{URL}} {{source_file.xml}}`
|