managair
asked on
NOT_FOUND_ERR when trying to DOM_Node.removeChild()
Hello experts,
I am using xerces-c-1.6 and VC++ on winNT.
I have a DOM_Document doc that looks something like this:
<root>
<elem1>
<!-- some child nodes -->
</elem1>
<elem2/>
<elem3/>
</root>
I also have a DOM_Element elem1 refering to <elem1>.
After extracting what I need from elem1, I want to remove it from doc:
doc.removeChild(elem1);
This call always returns with NOT_FOUND_ERR, although elem1 is a child of doc.
What am i doing wrong?
Is there another way to remove unwanted elements from a document using the DOM api?
thanks, gadi.
I am using xerces-c-1.6 and VC++ on winNT.
I have a DOM_Document doc that looks something like this:
<root>
<elem1>
<!-- some child nodes -->
</elem1>
<elem2/>
<elem3/>
</root>
I also have a DOM_Element elem1 refering to <elem1>.
After extracting what I need from elem1, I want to remove it from doc:
doc.removeChild(elem1);
This call always returns with NOT_FOUND_ERR, although elem1 is a child of doc.
What am i doing wrong?
Is there another way to remove unwanted elements from a document using the DOM api?
thanks, gadi.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
under the W3C DOM Model, if you use the oDoc.removeChild method, you can remove the immediate child nodes of the DOM Object e.g.
<?xml version="1.0"?> --- first child
<root> -- second child
<users>10</users>
</root>
<?xml version="1.0"?> --- first child
<root> -- second child
<users>10</users>
</root>
the removeChild is still applicable at the DOM object level but applies to the immediate child nodes
ASKER
indeed, when i explicitly refered to the node returned by getParentNode(), the removal worked.
why is my original attempt wrong? i guess the DOM specification team had a reason for this, but it seems strange that i can't simply remove a node through it's parent without explicitly calling getParentNode().