Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-382

Second traversal of XmlBeans DOM-implementation incorrect

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • Version 2.4
    • None
    • DOM
    • None
    • Windows Xp Professional, Sun JDK 1.5.0-16

    Description

      After parsing an XML file with the generic XmlObject.Factory.parse method, traversing the DOM representation the second time produces incorrect results. 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 although there have only been reading operations on the DOM model. The further call of getFirstChild() returns null although the previous call to hasChildNodes() returned true.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            andreas.kloeber Andreas Klöber

            Dates

              Created:
              Updated:

              Slack

                Issue deployment