Solved

NOT_FOUND_ERR when trying to DOM_Node.removeChild()

Posted on 2002-03-13
4
881 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
the removeChild is still applicable at the DOM object level but applies to the immediate child nodes
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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, …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now