Solved

NOT_FOUND_ERR when trying to DOM_Node.removeChild()

Posted on 2002-03-13
4
888 Views
Last Modified: 2012-05-04
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.
0
Comment
Question by:managair
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 100 total points
ID: 6860523
that's wrong...

under VB and with MSXML
============================

Dim oElem As MSXML2.IXMLDOMElement
Dim oParent As MSXML2.IXMLDOMElement
'MS's extension here
'The point is that we are getting the element
Set oElem = oXML.selectSingleNode("//elem1")
Set oParent = oElem.parentNode
oParent.removeChild(oElem)


The parent node is the only authorised element to remove immediate children found.

You could write a simple sub routine. Again under VB

Sub DeleteNode(ByRef oNode As MSXML2.IXMLDOMElement)
Dim oParent As MSXML2.IXMLDOMElement
Set oParent = oNode.parentNode
oParent.removeChild oNode
End Sub
0
 

Author Comment

by:managair
ID: 6860574
thanks for your reply b1xml2.

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().
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6860591
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>
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6860630
the removeChild is still applicable at the DOM object level but applies to the immediate child nodes
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question