Explore the tree structure of an XML document with xmllint’s shell mode.
xmllint is a command-line tool available as part of libxml2 (http://xmlsoft.org). It is included in distributions such as Cygwin (http://www.cygwin.com) and Red Hat Linux (http://www.redhat.com). You can also download xmllib2 individually from http://xmlsoft.org. xmllint has an interactive shell mode that lets you traverse an XML document’s tree structure as if it were a file structure, allowing you to examine any node in the tree discretely. Provided that you have an Internet connection, this shell mode will work on remote files as well as local ones. This hack will show you how it’s done.
While in the working directory, we first invoke the shell on an XML
xmllint --shell time.xml / >
A prompt appears (
>). The location in the tree
is shown to the left of the prompt (
/), but with
the depth of only one node. Enter the
to see information about the document or root node, and follow that
base command to see the base URI of the
document being explored:
/ > dir DOCUMENT version=1.0 encoding=UTF-8 URL=time.xml standalone=true / > base time.xml />
Move to a different node with
cd, followed by
dir, then by a
/ > cd time/atomic atomic > dir ELEMENT atomic ATTRIBUTE signal TEXT content=true atomic > cat <atomic signal="true"/> atomic >
dir gives you information about the node, and
cat gives you the XML representation ...