SWX

Team-Fly

SWX is an interesting piece of software, a SAX 1.0 parser that reads WAP Binary XML (WBXML). WBXML is a binary encoding of XML that is designed to reduce the size of XML documents. (See http://www.w3.org/TR/wbxml/ for more information.) If you're worried about data transmission times (as you may well be), you might consider encoding your XML at the server side to WBXML and using this parser on the client side.

Like some of the other parsers we've looked at, SWX needs some modifications before it will build in a MIDP environment. First, you will need to supply a dummy java.util.Locale class. If you're using the J2MEWTK, save the following in <J2MEWTK>/apps/<projectname>/src/java/util.

 package java.util; public class Locale { } 

In the org.xml.sax.helpers.ParserFactory class, replace the body of the no-argument makeParser() method with the following:

 String className = DEFAULT_PARSER; return makeParser(className); 

Finally, the convert() method in de.trantor.wap.WbxmlEncoder uses the writeTo() method of ByteArrayOutputStream, which is not defined in the MIDP environment. This is easy enough to fix. In the convert() method, find the following code:

 stringTableBuf.writeTo (out); buf.writeTo (out); 

Change the two calls as follows:

 out.write(stringTableBuf.toByteArray()); out.write(buf.toByteArray()); 

With these changes, SWX will build in a MIDP environment.

To actually use the parser, create an instance of de.trantor.wap.WbxmlParser and use it pretty much as you would a regular SAX 1.0 parser. For full SAX compatibility, a SAXWrapper class is provided. Basic parsing code looks a lot like any other SAX 1.0 parsing code:

 WbxmlParser p = new WbxmlParser(); // Set up a DocumentHandler named handler. p.setDocumentHandler(handler); p.parse(rawIn); 

Note 

The SWX package includes a utility class, WbxmlEncoder, which converts regular XML to WBXML. It's a little rough around the edges but can be used to convert XML documents to WBXML for testing. WbxmlEncoder itself depends on the com.sun.xml.parser.Parser class, which you may or may not have lying around on your system. I found it in my copy of Tomcat 3.1, in the lib/xml.jar file.


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