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

Second traversal of XmlBeans DOM-implementation incorrect

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: Version 2.4
    • Fix Version/s: None
    • Component/s: DOM
    • Labels:
      None
    • Environment:
      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

        1. xmlBeansTest.zip
          3 kB
          Andreas Klöber

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              andreas.kloeber Andreas Klöber
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: