Hi,
I have a problem working with a NodeIterator provided by
XPathAPI.selectNodeIterator.
First: What I want to achieve:
I want to delete specific Nodes from a dom tree.
Second: My Problem:
I get a NullPointerException deep down in
org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.nextNode(DOM2DTM.java:421)
While doing the following:
Node n = null;
while ((n = nl.nextNode()) != null) n.getParentNode().removeChild(n);
The Nodelist nl is the result of:
NodeIterator nl = XPathAPI.selectNodeIterator(doc,
"/root/data_field_category/child::*[attribute::data_field = \"1\"]");
Where doc is the DOM-Document, looking like:
<root>
<data_field_category>
<x data_field="1" category="2"/>
<x data_field="1" category="3"/>
<x data_field="2" category="2"/>
</data_field_category>
</root>
Please find attached the file <<Null.java>> reproducing the described Error.
The W3C's Document Object Model (DOM) Level 2 Traversal and Range
Specification states in Chapter 1, part 1.1.1.2. Robustness:
--8<--
A NodeIterator may be active while the data structure it navigates is being
edited, so an iterator must behave gracefully in the face of change.
Additions and removals in the underlying data structure do not invalidate a
NodeIterator; in fact, a NodeIterator is never invalidated unless its
detach() method is invoked.
-->8--
Am I wrong or is it a bug in apache-xml?
If I'm wrong, I would like to ask, how to achieve the described behaviour in
another way.
Thomas Kriegelstein