You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Wing Yew Poon (JIRA)" <xm...@xml.apache.org> on 2008/09/29 20:46:44 UTC

[jira] Updated: (XMLBEANS-382) Second traversal of XmlBeans DOM-implementation incorrect

     [ https://issues.apache.org/jira/browse/XMLBEANS-382?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wing Yew Poon updated XMLBEANS-382:
-----------------------------------

    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.


  was:
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.


        Summary: Second traversal of XmlBeans DOM-implementation incorrect  (was: Twice traversion of XmlBeans DOM-implementation fails)

> Second traversal of XmlBeans DOM-implementation incorrect
> ---------------------------------------------------------
>
>                 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
>         Attachments: xmlBeansTest.zip
>
>
> 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.

-- 
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: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org