You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Stefan Rauch <sr...@uos.de> on 2000/06/14 09:55:30 UTC

bug in serializing dom ??

Hi!
 
I posted this some time ago in the ibm "xml-parser for java" newsgroup but didin't get an answer.
I would be glad if anybody could give me a hint, what I'm missing. I had a rough view on the mailing lists archive but couldn't find a solution there - so here is my question:

I've got a problem with the newer xerces-releases (1.04 - May 2000 and higher - up to xerces1.1.1)

I created several classes using the org.apche.xerces.parsers.DOMParser and all of them work fine with the xerces.jar from xerces1.03, but right now they fail whenever I try to access an instance of the DocumentImpl which has been serialized before.

A simple example (existing of two classes - The first class reads in xml, serializes it and writes it to a ObjectOutputStream [DOMOut] and the second one reads the serialized dom from ObjectInputStream and tries to get a given searchelement [DOMIn]):

[DOMOut]:
...
  DOMParser parser = new DOMParser();
  FileReader in = new FileReader(argv[0]);
  InputSource ins = new InputSource(in);
  parser.parse(ins);
  DocumentImpl doc = (DocumentImpl)parser.getDocument();
  ObjectOutputStream out = new ObjectOutputStream(System.out);
  out.writeObject(doc); out.flush();
...
[DOMIn]:
...
  ObjectInputStream in = new ObjectInputStream(System.in);
  DocumentImpl doc = (DocumentImpl) in.readObject();
  NodeList nl = doc.getElementsByTagName(argv[0]);
  if (nl.getLength()==0)
     System.out.println(argv[0] + ": is not in the document!");
  else {
      NodeImpl node = (NodeImpl) nl.item(nl.getLength()-1);
      System.out.println(node.getNodeName() + ": " + (node.getFirstChild()).getNodeValue());
   }
...

This is what I do with the classes:

javac DOMOut.java
javac DOMIn.java
java DOMOut xmltestfile.xml > xx

This works so far

java DOMIn searchelem < xx

This one breaks! I get the following exception (using xerces1.04, but it's very similar to the one using xerces1.1.1):
java.lang.NullPointerException:
        at org.apache.xerces.dom.DeferredDocumentImpl.clearChunkIndex(DeferredDocumentImpl.java:1534)
        at org.apache.xerces.dom.DeferredDocumentImpl.getNodeType(DeferredDocumentImpl.java:1036)
        at org.apache.xerces.dom.DeferredDocumentImpl.getNodeType(DeferredDocumentImpl.java:1020)
        at org.apache.xerces.dom.DeferredDocumentImpl.synchronizeChildren(DeferredDocumentImpl.java, Compiled Code)
        at org.apache.xerces.dom.ParentNode.hasChildNodes(ParentNode.java:241)
        at org.apache.xerces.dom.DeepNodeListImpl.nextMatchingElementAfter(DeepNodeListImpl.java, Compiled Code)
        at org.apache.xerces.dom.DeepNodeListImpl.item(DeepNodeListImpl.java, CompiledCode)
        at org.apache.xerces.dom.DeepNodeListImpl.getLength(DeepNodeListImpl.java:151)
        at IbmDOMIn2.main(IbmDOMIn2.java:30)

Where IbmDOMIn2.main 30 is the following line:
         if (nl.getLength()==0)

Some Notes:
The DocumentImpl exists. I tried it out by printing out the docs last Node's Value.
Even if use the wildcard (*) in doc.getElementsByTagName() the returning NodeList seems to be broken.
It is note an error in getLength(). If I call (e.g.) nl.item() first there's also a NullPointerException

Are there any changes between xerces1.03 and xerces1.04 in Serialization I'm missing?
As I mentioned before this example works fine with xerces1.03 but I would like to use the newer versions...
I would be very pleased if anyone could help me soon!

Thanks

Stefan.