Hi Shekhar,

could you send an example of an xml file that fails your scenerio and could you also send a code sample that I can execute (preferably a junit test, but a class with a main-method is also ok) and that illustrates the problem.

thanks,
Maarten

Shekhar Srivastava wrote:

I am using parser that comes with JDK 1.4.1. I am not sure abt the version :( . In order to run a simple prog like the one whose results I am enclosing, all I need is DOM4J-full.jar with rt.jar for JDK 1.4.1

Anyway, I serialized the document where this execption occurred and saved it as test.xml

Then I opened it with XMLSpy and then saved it as test1.xml so that the file gets structured properly.

I did the following:

1. Parsed both these files using DOM4J and executed XPath using DOM4J API. Everything went fine
2. Parsed both these files using Xerces and executed XPath using Xalan API. Again everything went fine
3. Parsed both of these using DOM4J and wrote the DOM4J document to w3c document and executed XPath using Xalan API which is the case in our application.


This time for test1.xml (file saved with XMLSpy) there was no exception.
but for test.xml I am getting the same exception.


What I fail to understand is that how come an XML just by formatting it properly can stop giving exceptions !!!!

Ne ideas????

With best regards,
Shekhar Srivastava

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



Hi Shekhar,


Which version of Xalan do you use? (use org.apache.xalan.Version for this)

The problem could be the DOM implementation of DOM4J which is very basic and is far from DOM compliant at the moment. What happens if you set the documentClass of the DOMWriter to "org.apache.xerces.dom.DocumentImpl" ?

regards,
Maarten

Shekhar Srivastava wrote:



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








-------------------------------------------------------
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





------------------------------------------------------- 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_id=1470&alloc_id=3638&op=click _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to