[
https://issues.apache.org/jira/browse/XERCESJ-1421?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13020644#comment-13020644
]
Thiwanka Somasiri commented on XERCESJ-1421:
--------------------------------------------
I wrote a sample program to demonstrate the scenario described above.
sample.xml :
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Thiwanka</to>
<from>Erangi</from>
<heading>Apache</heading>
<body>Xerces</body>
</note>
InternaRemoveChildTest class :
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.SAXException;
import java.io.IOException;
import org.xml.sax.InputSource;
import org.w3c.dom.Document;
import org.w3c.dom.*;
public class InternaRemoveChildTest
{
public void parser()
{
InputSource is = new
InputSource("/home/thiwanka/workspace/Test/src/sample.xml");
DOMParser parser = new DOMParser();
try
{
parser.parse(is);
// System.out.println("The sample.xml is well-formed.");
Document document = parser.getDocument();
Node node = document.getDocumentElement();
System.out.println("Document Element node name : " +
node.getNodeName() + "\n");
System.out.println("\n___________________DOM nodes before
removing the child___________________\n");
processNodeRecursively(node);
removeNode(document);
}
catch (SAXException e)
{
System.out.println("The sample.xml is not well-formed");
}
catch (IOException e)
{
System.out.println(
"The parser could not check the sample.xml IOException"
);
}
}
public void removeNode(Document document)
{
//Create the node to be removed - the first child in this
specific case
Node node = document.getDocumentElement().getFirstChild();
System.out.println("Node Name of the node to be removed : " +
node.getNodeName());
//Remove the node
Node removedNode =
document.getDocumentElement().removeChild(node); //Start debugging from this
point
System.out.println("Node Name of the node to be removed : " +
removedNode.getNodeName());
//Access the DOM tree
System.out.println("\n___________________DOM nodes after
removing the child___________________\n");
processNodeRecursively(document.getDocumentElement());
}
public void processNodeRecursively(Node node)
{
for (Node child = node.getFirstChild() ; child != null ;
child = child.getNextSibling())
{
System.out.println("Node name : " +
child.getNodeName()+ " " + "Node value : " + child.getNodeValue());
processNodeRecursively(child);
}
}
public static void main(String[] args)
{
InternaRemoveChildTest test = new InternaRemoveChildTest();
test.parser();
}
}
Note : Check the values at "checkNormalizationAfterRemove" method in
"ParentNode" class.
> Temporary inconsistent data inside Xerces2-J when removing a first child of a
> node.
> -----------------------------------------------------------------------------------
>
> Key: XERCESJ-1421
> URL: https://issues.apache.org/jira/browse/XERCESJ-1421
> Project: Xerces2-J
> Issue Type: Improvement
> Components: DOM (Level 3 Core)
> Affects Versions: 2.9.1
> Reporter: Ludger Bünger
> Assignee: Michael Glavassevich
> Priority: Minor
> Attachments: PreviousSiblingInconsistentDataPatch.txt
>
>
> When removing a first child, currently there is a local field inside
> ParentNode.internalRemoveChild that contains inconsistent data.
> Since in this specific case the following code still performs correct, there
> is currently no harm done.
> However I think it should be fixed nonetheless since future changes to the
> code might cause problems.
> And here the description of the issue:
> Xerces2-J uses an internal optimization by overloading the
> ChildNode.previousSibling field.
> 1) If a node has a previous sibling, this field contains the previous sibling.
> 2) if a node is the first child of it's parent (and thus has no previous
> sibling), this field is re-used for a different purpose and contains the last
> sibling thus allowing quick access to the end of a node list
> Now ChildNode.internalRemoveNode stores a reference to the previousSibling of
> the removed node for normalization checking purposes in the local field
> oldPreviousSibling.
> However this is done after removal of the node is already done but before
> null'ing of the tree structure fields of the node.
> Since this node has already been removed, the isFirstChild() check fails and
> instead of 'null' the last sibling is stored in the oldPreviousSibling field.
> By chance the normalization checking code still works correct if the previous
> sibling field contains the last sibling instead of the correct value 'null'
> but this still should be fixed.
> See attached patch.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]