7. XML and PYX format

Here is synopsis for 'xml pyx' command:

XMLStarlet Toolkit: Convert XML into PYX format (based on ESIS - ISO 8879)
Usage: xml pyx {<xml-file>}
where
   <xml-file> - input XML document file name (stdin is used if missing)

The PYX format is a line-oriented representation of
XML documents that is derived from the SGML ESIS format.
(see ESIS - ISO 8879 Element Structure Information Set spec,
ISO/IEC JTC1/SC18/WG8 N931 (ESIS))

A non-validating, ESIS generating tool originally developed for
pyxie project (see http://pyxie.sourceforge.net/)
ESIS Generation by Sean Mc Grath http://www.digitome.com/sean.html

XMLStarlet is a command line toolkit to query/edit/check/transform
XML documents (for more information see http://xmlstar.sourceforge.net/)

EXAMPLE

xml pyx input.xml

Input (input.xml)

<books>
<book type='hardback'>
<title>Atlas Shrugged</title>
<author>Ayn Rand</author>
<isbn id='1'>0525934189</isbn>
</book>
</books>

Output

(books
-\n
(book
Atype hardback
-\n
(title
-Atlas Shrugged
)title
-\n
(author
-Ayn Rand
)author
-\n
(isbn
Aid 1
-0525934189
)isbn
-\n
)book
-\n
)books

PYX is a line oriented format for XML files which can be helpful (and very efficient) when used in combination with regular line oriented UNIX command such as sed, grep, awk.

'depyx' option is used for conversion back from PYX into XML.

EXAMPLE (Delete all attributes). This should work really fast for very large XML documents.

xml pyx input.xml | grep -v  "^A" | xml depyx

Output

<books>
<book>
<title>Atlas Shrugged</title>
<author>Ayn Rand</author>
<isbn>0525934189</isbn>
</book>
</books>

Here is an article which describes how PYX format can be used to grep XML. http://www-106.ibm.com/developerworks/xml/library/x-matters17.html