Presents your JAVA E-NEWSLETTER for December 19, 2002 <-------------------------------------------> PARSE YOUR XML DOCUMENTS WITH NANOXML Standard XML parsers are often large, unwieldy packages. However, smaller options do exist and, though they may be tiny in size, they are most likely big in basic functionality. One such XML parser is NanoXML. NanoXML is a tiny open source XML parser project. It installs from a 6KB jar file, perfect for using on PDAs or other small footprint devices. NanoXML is also very simple to use and works fine in Java 1.1. The central class in NanoXML is the nanoxml.XMLElement class. An XML string is passed into an instance of this class to be parsed and can then have its components viewed and accessed. Here's an example: import java.util.Enumeration; import nanoxml.XMLElement; public class Parse { static public void main(String[ ] args) { // test xml String xml = "personplaceanimal"; // make an XMLElement XMLElement root = new XMLElement( ); // parse root.parseString(xml, 0); // the root tag System.out.println("root="+root.getTagName( )); // loop over each child, printing out its name, its 'num' // attribute and its contents Enumeration enum = root.enumerateChildren( ); while(enum.hasMoreElements( )) { XMLElement elem = (XMLElement)enum.nextElement( ); System.out.println("tag="+elem.getTagName( )); System.out.println("num="+elem.getProperty("num")); System.out.println("data="+elem.getContents( )); } } } This is the output from this test: root=example tag=one num=1 data=person tag=two num=2 data=place tag=three num=null data=animal In addition, NanoXML is able to run as a Standard SAX parser by including the 2KB nanoxml-sax.jar and setting the org.xml.sax.parser property to nanoxml.sax.SAXParser. A SAX parser under 9KB is pretty impressive when you consider that the larger competitors are struggling to stay under 200KB. You can find more information about NanoXML at its home page. http://nanoxml.n3.net/ ----------------------------------------