• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 894
  • Last Modified:

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:

  <!-- some child nodes -->

I also have a DOM_Element elem1 refering to <elem1>.
After extracting what I need from elem1, I want to remove it from doc:


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.
  • 3
1 Solution
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

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
managairAuthor Commented:
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().
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
the removeChild is still applicable at the DOM object level but applies to the immediate child nodes

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now