Actually its somewhat complicated. In the first release the application was based on 
Xerces. Then we realized that if we switch to DOM4J, the performance improves a lot. 
Since it would have been very expensive to rewrite the whole application we used DOM4J 
to parse the document and then wrote DOM4J document to W3C document. Still the time 
taken for processing and the memory usage dropped significantly. 

While the code works for most of the document, for some (and I don't know why at the 
best it looks random), during execution of XPATH we are getting the following error. 

Also, if I execute the same XPATH on DOM4J document directly, no error is reported. 
Similarly if I parse the file using Xerces and then execute same XPATH on W3C document 
obtained thus, again no erro is reported. So I guess the problem is in writing DOM4J 
document to W3C document. 

Am I missing something here?? Please take a look at the code below

SAXReader objSAXReader = new SAXReader ( false );
//set the SAXReader features to load the DTD

objSAXReader.setFeature ( 
"http://apache.org/xml/features/nonvalidating/load-external-dtd";, true );
//resolve the entities. This method gets the public dtd declaration and loads the dtd 
from the configured location

objSAXReader.setEntityResolver ( this );
//set the error handler for SAX reader

objSAXReader.setErrorHandler ( this );
//ignore the comments in xml document

objSAXReader.setIgnoreComments ( true );
//parse the strFileName to get the dom4j Document object

org.dom4j.Document docDOM4JDocument = objSAXReader.read ( strFileName );

Once we have the DOM4J Document, then we writet he document to w3c document as the 
rest of the application was written based on this 

DOMWriter objDOMWriter = new DOMWriter ();
objDOMWriter.setDomDocumentClass ( Class.forName ( "org.dom4j.dom.DOMDocument" ) );

org.w3c.dom.Document docW3CDocument = objDOMWriter.write ( docDOM4JDocument );

//Conversion of DOM4J document into w3c document results in loss of DocType element
//get the doctype element from DOM4J document and append to W3C document
org.dom4j.DocumentType objDOM4JDocType = docDOM4JDocument.getDocType ();

//get the DOMImplamentation of W3C document.
DOMImplementation objDOMImplementation = docW3CDocument.getImplementation ();

// Create the W3C document type
DocumentType objW3CdocType = objDOMImplementation.createDocumentType ( "DOCTYPE",
                                                      objDOM4JDocType.getPublicID (),
                                                      objDOM4JDocType.getSystemID () );



regards,
Shekhar

-----Original Message-----
From: bob mcwhirter [mailto:[EMAIL PROTECTED] 
Sent: Friday, April 02, 2004 1:49 AM
To: Shekhar Srivastava
Cc: [EMAIL PROTECTED]
Subject: Re: [dom4j-user] Getting Null Pointer exception in XPATH execution



It looks like you're using Xerces for the xpath stuff
instead of the built-in Jaxen xpath impl.

Look at the API for Branch/Element, and you'll see that
it directly supports XPath using the integrated Jaxen impl.

        -bob

On Thu, 1 Apr 2004, Shekhar Srivastava wrote:

> Hi All,
>
> I am new to DOM4J and I am getting the following exception in an 
> existing system that I am supporting. We are using JDK 1.4.1.
>
> NodeIterator nl = XPathAPI.selectNodeIterator( doc, xql ); while ( ( n 
> = nl.nextNode () ) != null ) {
>       //...some processing
> }
>
> the xql passed is "//docinfo" and when I serialised the document 
> passed, I find that the node is present. Also this problem is occuring 
> only for some xml files. Most of the files are getting through without 
> any error.
>
> java.lang.NullPointerException
> at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.nextNode(DOM2DTM.java:347)
> at 
> org.apache.xml.dtm.ref.DTMDefaultBaseTraversers$IndexedDTMAxisTraverser.getNextIndexed(DTMDefaultBaseTraversers.java:576)
> at 
> org.apache.xml.dtm.ref.DTMDefaultBaseTraversers$DescendantTraverser.next(DTMDefaultBaseTraversers.java:742)
> at org.apache.xpath.axes.DescendantIterator.nextNode(DescendantIterator.java:274)
> at org.apache.xpath.axes.LocPathIterator.runTo(LocPathIterator.java:802)
> at org.apache.xml.dtm.ref.DTMNodeList.<init>(DTMNodeList.java:114)
> at org.apache.xpath.objects.XNodeSet.nodelist(XNodeSet.java:384)
> at org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:205)
> at org.apache.xpath.XPathAPI.selectNodeList(XPathAPI.java:182)
> at foundation.utils.FTKConfigAccessor.executeXpath(FTKConfigAccessor.java:1563)
>
>
> regards,
> Shekhar Srivastava,

--
Bob McWhirter        [EMAIL PROTECTED]
The Werken Company   http://werken.com/


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to