NanoXML

Team-Fly

NanoXML, like MinML, does not support mixed content. Although the basic download does not compile in the MIDP environment, Eric Giguere has ported NanoXML to the CLDC. A modified source file is available from http://nanoxml.sourceforge.net/kvm.html.

Building NanoXML on MIDP is a matter of substituting Eric Giguere's kXMLElement.java for the XMLElement.java that comes with NanoXML.

NanoXML follows the DOM model, where an entire document is read into memory and can be examined later. Parsing the document is a matter of creating an instance of kXMLElement and calling one of its parse methods. There are methods for parsing Strings, character arrays, and Readers. In a MIDlet you could parse a file like this:

 String filename = "example1.xml"; InputStream rawIn = this.getClass().getResourceAsStream(filename); Reader in = new InputStreamReader(rawIn); try {   kXMLElement p = new kXMLElement();   p.parseFromReader(in); } catch (Exception e) { // Handle exceptions. } 

Once the document is fully parsed, you can examine its contents using getChildren() or enumerateChildren() methods, which return collections of nested kXMLElements.

NanoXML also offers the possibility of modifying a document and writing it back out to a stream. This is probably not very useful on a MIDP device, but it's an interesting possibility nevertheless.


Team-Fly


Wireless Java. Developing with J2ME
ColdFusion MX Professional Projects
ISBN: 1590590775
EAN: 2147483647
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net