Solved

NOT_FOUND_ERR when trying to DOM_Node.removeChild()

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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