developerlife.com (tm)
home -> New parsers


New Parsers and code changes from old versions
New Parsers
Author: Nazmul Idris
Date: March 27 1999.
Copyright Nazmul Idris 1998-2006. All Rights Reserved. 
Index
New parser versions
New parser released
Code changes from old parsers
Code to instantiate DOM document objects for 3 parsers
Downloading the parsers


go to topNew parser versions
After Tutorial1 and 2 were released (i.e., after Feb. 12 1999), Sun and IBM have both released new versions of their parsers. They are:
  • Sun Project X Technology Release 1 
  • IBM XML Parser for Java v2.0.4. 
The code in the two tutorials (Tutorial 1 and 2) works unchanged for the new IBM parser, but we recommend using the new way of instantiating the IBM parser over the old way. The new IBM parser has 2 modes of operation: fast and backward compatible (slow). The old way of instantaiting the parser makes it run in backward compatible mode. The new mode is really fast!

The new Sun parser breaks the code (when instantiating a DOM document object) in the 2 tutorials. This is because the XMLDocumentBuilder class has been deprecated and replaced with XMLDocument. This is why the code in the tutorials (for the Sun parser) might be throwing exceptions when you run them with the new parser version.

go to topNew parser released
On open source parser from OpenXML (openxml.org) was released recently. We have included support for this parser in all our new code (from Mar 18 1999). We have also done a performance review of all three parsers (Sun, IBM and OpenXML). The version of OpenXML parser that we have included is OpenXML v1.0.4. 
go to topCode changes from old parsers
The only change between the old Sun parser and the new one is one line, the line used to instantiate a DOM document object. Instead of using XMLDocumentBuilder.createXmlDocument( url ); use XMLDocument.createXmlDocument( url );. Just one line should fix the old code.

The new IBM parser has a new way of instantiating DOM document objects that has changed considerably since the old version. You can still use the old way to instantiate a DOM object, but this method creates a "backward-compatible" IBM XML parser which is slow. If you use the new way, you get the speed enhancements of the new IBM parser. 

  • The import statement has changed from com.ibm.xml.parser.* to com.ibm.xml.parsers.*
  • You can't use an InputStream create a DOM document object from anymore; you have to use a String (that contains a URL to an XML file). 
  • The method to get a Document object is now getDocument(); instead of readStream(i).
go to topCode to instantiate DOM 1.0 document objects from 3 parsers
The code to instantiate a DOM object using the Sun Project X Technology Release 1 parser is:

import com.sun.xml.tree.*;
import org.w3c.dom.*;

try {
    String url = 
        "http://beanfactory.com/xml/AddressBook.xml";
    Document doc = 
        XmlDocument.createXmlDocument(url);
    }
catch(Exception e){}

The code to instantiate a DOM object using the IBM XML Parser for Java version 2.0.4 is:

import com.ibm.xml.parsers.*;
import org.w3c.dom.*;

try {
    String url = 
        "http://beanfactory.com/xml/AddressBook.xml";
    DOMParser ps = new DOMParser();
    ps.parse( url );
    Document doc = ps.getDocument();
    }
catch( Exception e ){}

The code to instantiate a DOM object using the OpenXML v1.0.4 parser is:

import org.w3c.dom.*;
import org.openxml.*;
import org.openxml.io.*;
import org.openxml.parser.*;
import org.openxml.DOMFactory.*;

try { 
    URL u = new URL(
        "http://beanfactory.com/xml/AddressBook.xml");
    InputStream is = u.openStream();
    BufferedReader br = new BufferedReader(
        new InputStreamReader(is) );
    org.openxml.io.Parser ps = 
        DOMFactory.createParser( br , "whatever" );
    Document doc = ps.parseDocument();
    }
catch(Exception e){}

Please note that a class named Parser exists in the IBM and OpenXML packages. This is why the OpenXML Parser class is prefixed with its package name. This would be necessary only if you were using both the IBM and OpenXML parsers in the same class.
 

go to topDownloading the parsers
Please go to the tools section to actually download the Parsers themselves.

I hope you enjoyed this article, I will have put updates on parsers on this page when the become available, so stay tuned and keep coming back :). Click here to send me any feedback/comments.

 

 
Web developerlife.com
Click here to send comments/feedback
Copyright Nazmul Idris 1999-2006. All Rights Reserved.
Last updated June 24 2006.