Solved

NOT_FOUND_ERR when trying to DOM_Node.removeChild()

Posted on 2002-03-13
4
887 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

Suggested Solutions

Title # Comments Views Activity
Adding Namespace to the second node of the xml 16 82
Convert XML to excel12book 5 36
XML XSLT If loop 4 38
Retreiving SOAP FAULT messages using classical ASP 14 48
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

751 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