H
Hoss
Hello.
Because IE and Mozilla have such completely different XML
implementations, I have created a class to handle general XML tasks,
such as iterating over nodes given an xpath, evaluating an xpath, ect.
It does all the branching for the different implementations within
itself. I am working on a new method for this class that will, given an
xpath, remove all nodes that match from the document. It works great in
IE, heres the IE code.
var nodeList = this.xdoc.selectNodes(xpath);
for(var x = 0; x < nodeList.length; x++)
{
nodeList[x].parentNode.removeChild(nodeList[x]);
}
However, Mozilla has a different way of doing things, and to evaluate
an xpath you have to specify if you want an iterator result, a snapshot
result, or a firstnode result type. Heres the problem:
If I return an iterator results type from the xpath, and then iterate
over the results, the iterator becomes invalid once I use the iterator
to modify the document tree . . . so that wont work.
If I return a snapshopt type from the xpath, and then loop over that,
each item is now disconnected from the document tree and modifying them
doesnt affect the document tree at all. So that doesnt work either.
Surely someone has tried this before ??? Heres my best efforts in
Firefox
var iterator = this.xdoc.evaluate(xpath, this.xdoc, null,
XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
var theNode = iterator.iterateNext();
while(theNode)
{
theNode.parentNode.removeChild(theNode);
theNode = iterator.iterateNext();
}
Because IE and Mozilla have such completely different XML
implementations, I have created a class to handle general XML tasks,
such as iterating over nodes given an xpath, evaluating an xpath, ect.
It does all the branching for the different implementations within
itself. I am working on a new method for this class that will, given an
xpath, remove all nodes that match from the document. It works great in
IE, heres the IE code.
var nodeList = this.xdoc.selectNodes(xpath);
for(var x = 0; x < nodeList.length; x++)
{
nodeList[x].parentNode.removeChild(nodeList[x]);
}
However, Mozilla has a different way of doing things, and to evaluate
an xpath you have to specify if you want an iterator result, a snapshot
result, or a firstnode result type. Heres the problem:
If I return an iterator results type from the xpath, and then iterate
over the results, the iterator becomes invalid once I use the iterator
to modify the document tree . . . so that wont work.
If I return a snapshopt type from the xpath, and then loop over that,
each item is now disconnected from the document tree and modifying them
doesnt affect the document tree at all. So that doesnt work either.
Surely someone has tried this before ??? Heres my best efforts in
Firefox
var iterator = this.xdoc.evaluate(xpath, this.xdoc, null,
XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
var theNode = iterator.iterateNext();
while(theNode)
{
theNode.parentNode.removeChild(theNode);
theNode = iterator.iterateNext();
}