Since you're already using xmlstarlet
you may as well continue using it.
The xmlstarlet
tool has an el
(elements
) sub-command which is used to "Display element structure of XML document".
By default, it outputs data like this:
$ xmlstarlet el /usr/X11R6/share/xcb/ge.xml
xcb
xcb/request
xcb/request/field
xcb/request/field
xcb/request/reply
xcb/request/reply/pad
xcb/request/reply/field
xcb/request/reply/field
xcb/request/reply/pad
You may also get attributes:
$ xmlstarlet el -a /usr/X11R6/share/xcb/ge.xml
xcb
xcb/@header
xcb/@extension-xname
xcb/@extension-name
xcb/@major-version
xcb/@minor-version
xcb/request
xcb/request/@name
xcb/request/@opcode
xcb/request/field
xcb/request/field/@type
xcb/request/field/@name
xcb/request/field
xcb/request/field/@type
xcb/request/field/@name
xcb/request/reply
xcb/request/reply/pad
xcb/request/reply/pad/@bytes
xcb/request/reply/field
xcb/request/reply/field/@type
xcb/request/reply/field/@name
xcb/request/reply/field
xcb/request/reply/field/@type
xcb/request/reply/field/@name
xcb/request/reply/pad
xcb/request/reply/pad/@bytes
See also xmlstarlet el --help
.
Using the val
(validate
) sub-command ("Validate XML document(s) (well-formed/DTD/XSD/RelaxNG)"), xmlstarlet
may validate your XML document for you. It will, by default, just check whether the document is well formed, but it may also validate your document against a provided XSD schema, the document's DTD, or an Relax-NG schema.
See also xmlstarlet val --help
.
xmlstarlet
that will do this for you already.