The package "xml tools" is a simple (Perl) wrapper around some XML-inspecting tools that I often use, and which I find quite handy.
How to get it
How to invoke it
The general invocation is xml ACTION ARGS
, where the action defines what happens. To see usage information, just run xml
and it'll show what's possible. The below sections show in general what xml
can do. Refer to the usage information to see full lists of options (flags) - i.e., start xml
xml prettyprint FILE
Prettyprints the named file, output appears on stdout
. Use file name - to read input from stdin. The optional flag -o
overwrites the file "in place".
Note that prettyprinting can modify the literal contents (though not the semantics). Particularly, <root><trunk/></root>
will get converted to
xml xpath FILE
This is a simple inspection method. All non-empty leaves are shown in an xpath format.
<leaf color="green">A bug sits here.</leaf>
<leaf>This leaf is not occupied.</leaf>
<leaf color="brown">This leaf is about to fall off.</leaf>
leads to the output:
/root/@material = wood
/root/trunk/branch/leaf/@color = green
/root/trunk/branch/leaf = A bug sits here.
/root/trunk/branch/leaf = This leaf is not occupied.
/root/trunk/branch/leaf/@color = brown
/root/trunk/branch/leaf = This leaf is about to fall off.
xml xsd FILE(s)
Shows the XSD (XML Schema Defintion) declarations of the given files.
xml xsdcheck FILE(s)
Per file, the XSD type is determined, and the file is checked against the proper XSD. XSD's are expected in /usr/local/lib/xml/xsd/
If your XML file has an XSD that isn't present in /usr/local/lib/xml/xsd/
, then either:
- Add the XSD to that directory, or
- Invoke the script as xml -x myfile.xsd FILE(s), this allows you to explicitly state the XSD type and file.
xml yaml FILE
This is another quick-inspector. The above shown XML appears as YAML:
- color: green
content: A bug sits here.
- This leaf is not occupied.
content: This leaf is about to fall off.