|
Re: DOM : removeall nodes with xpath: msg#00029mozilla.devel.dom
rvj wrote: Ive attempted to use the currentNode.parentNode.removeChild(currentNode) I posted code example where XPath created a snapshot and then an iteration through the snapshot items removed them e.g. var xmlDocument = document.implementation.createDocument('', 'root', null); xmlDocument.addEventListener( 'load', function testAttributeDeletion (evt) { var xpathResult = xmlDocument.evaluate( '//node[@about = "node:3"]', xmlDocument, null, 7, null ); for (var i = 0; i < xpathResult.snapshotLength; i++) { var currentNode = xpathResult.snapshotItem(i); currentNode.parentNode.removeChild(currentNode); } alert(new XMLSerializer().serializeToString(xmlDocument)); }, false ); xmlDocument.load('test2004101202.xml') If I do that with your example document below all is fine, the alert shows the XML document as expected with one <node> removed. ************************************************** Why that odd loop to go through the document? I think the problem you run into is that you use nextSibling.nextSibling trying to move from element to element node however after the removal of one <node about="node:3" label="hello"/> element node there are two adjacent white space text nodes between <node about="node:2" /> and <node about="node:4" /> So the document is fine, only your loop is not adequate to loop through element nodes, consider using xmlDocument.getElementsByTagName('node') if you want to loop through the element nodes. -- Martin Honnen http://JavaScript.FAQTs.com/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: DOM : removeall nodes with xpath: 00029, rvj |
|---|---|
| Next by Date: | Re: DOM : removeall nodes with xpath: 00029, rvj |
| Previous by Thread: | Re: DOM : removeall nodes with xpathi: 00029, rvj |
| Next by Thread: | Re: DOM : removeall nodes with xpath: 00029, rvj |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |