Twice traversion of XmlBeans DOM-implementation fails
-----------------------------------------------------
Key: XMLBEANS-382
URL: https://issues.apache.org/jira/browse/XMLBEANS-382
Project: XMLBeans
Issue Type: Bug
Components: DOM
Affects Versions: Version 2.4
Environment: Windows Xp Professional, Sun JDK 1.5.0-16
Reporter: Andreas Klöber
Priority: Critical
After parsing an XML-file with the generic XmlObject.Factory.parse-method the
traversion of the DOM-Reprsentation fails the second time. The following
shortened example demonstrates this:
content of example_fail.xml:
<a>
<!--comment-->
<b>example</b>
</a>
example-code:
<code>
import java.io.File;
import org.apache.xmlbeans.XmlObject;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
public class XmlBeansBug {
private static String EXAMPLE_XML_FILE_FAIL = "example_fail.xml";
private static void traverseNodes(Node node){
//get first child (<a>-node)
Node aNode = node.getFirstChild();
//get next child (#TEXT-node)
Node textNode1 = aNode.getFirstChild();
//get next sibling (#COMMENT-node)
Node commentNode = textNode1.getNextSibling();
//get next sibling (second #TEXT-node)
boolean hasCommentNodeChildes = commentNode.hasChildNodes();
System.out.println(" has comment-node child-nodes: " +
hasCommentNodeChildes);
if(hasCommentNodeChildes){
Node chilfOfCommentNode = commentNode.getFirstChild();
System.out.println(" child of comment-node is: " +
chilfOfCommentNode);
}
Node textNode2 = commentNode.getNextSibling();
//get next sibling (<b>-node)
Node bNode = textNode2.getNextSibling();
}
public static void main(String[] args) throws Throwable {
XmlObject exampleFailXmlObject = XmlObject.Factory
.parse(new File(EXAMPLE_XML_FILE_FAIL));
Document exampleFailDocument = (Document) exampleFailXmlObject
.getDomNode();
System.out.println("First run:");
traverseNodes(exampleFailDocument);
System.out.println("Second run:");
traverseNodes(exampleFailDocument);
}
}
</code>
The first time hasChildNodes() on the comment-node returns false, which is
correct. The second time it returns true althoughthere have only been reading
operations on the DOM-model. The further call of getFirstChild() returns null
although the previous call to hasChildNodes() returned true.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]