Thank you so much! I had been pulling out my hairs with this one. Too bad you can't 
see more meaningful error messages.

Rafi

-----Original Message-----
From:   tom dyson [SMTP:[EMAIL PROTECTED]]
Sent:   Friday, December 14, 2001 8:00 AM
To:     [EMAIL PROTECTED]
Subject:        Re: [cf-xml] Error with removechild, insertbefore and replacechild

Hi Rafi,

Your code fails because the 'baby' element is not a child of the root
element (it's a grandchild). The removeChild method must be used with a
direct ancestor of the element to be deleted: you can access this ancestor
using the parentNode property. Here's the code you need:

<cfobject action="create" class="MSXML2.DOMDocument" name="xmldoc">
<cfset xml = "<mother><firstdaughter>This is a test</firstdaughter>
<seconddaughter><baby>Test</baby></seconddaughter></mother>">
<cfscript>
xmldoc.loadXML('#xml#');
// specify the condemned element...
todelete=xmldoc.selectSingleNode("mother/seconddaughter/baby");
// find its parent
todeleteparent = todelete.parentNode;
// remove the parent's child
deleteSuccess = todeleteparent.removeChild(todelete);
// prove it worked
writeoutput('before: ' & htmleditformat(xml));
writeoutput('<hr />after: ' & htmleditformat(xmldoc.xml));
</cfscript>

Tom

-----------------+
tom dyson
t: +44 (0)1608 811870
m: +44 (0)7958 752657
http://torchbox.com



-----------------------+
cf-xml mailing list
list: [EMAIL PROTECTED]
admin: [EMAIL PROTECTED]
home: http://torchbox.com/xml

Reply via email to