I think it's a bit more involved than that...

I just copied this one out of some code I was working on recently, so I know
it should work, but I changed a bunch of variable names, so it could have a
bug in it:


<cffunction name="addNode">
        <cfargument name="xmlDoc">
        <cfargument name="newNode">
        <cfargument name="oldNode">
        <cfset var key = "">
        <cfset var index = "">
        <cfset var i = "">
        <cfif len(trim(oldNode.xmlComment))>
                <cfset newNode.xmlComment = trim(oldNode.xmlComment)>
        </cfif>
        <cfset newNode.xmlAttributes = oldNode.xmlAttributes>
        <cfset newNode.xmlText = trim(oldNode.xmlText)>
        
        <cfloop from="1" to="#arrayLen(oldNode.xmlChildren)#" index="i">
                <cfset newNode.xmlChildren[i] =
xmlElemNew(xmlDoc,oldNode.xmlChildren[i].xmlName)>
                <cfset
addNode(xmlDoc,newNode.xmlChildren[i],oldNode.xmlChildren[i])>
        </cfloop>

</cffunction>

Called like this:

<cfset addedNode = xmlElemNew(someXMLDoc,'tagName')>
<cfset addNode(someXMLDoc,addedNode,oldNode)>

Spike

--------------------------------------------
Stephen Milligan
Code poet for hire
http://www.spike.org.uk

Do you cfeclipse? http://cfeclipse.tigris.org 


 

>-----Original Message-----
>From: [EMAIL PROTECTED] 
>[mailto:[EMAIL PROTECTED] On Behalf Of Mark M
>Sent: Thursday, May 27, 2004 7:04 PM
>To: CFAussie Mailing List
>Subject: [cfaussie] Re: Inserting xml node
>
>I believe this has to do with the fact that an XML element 
>knows it's parent.
>
>So you may have to do something like:
>
><cfscript>
>aryDetails =  xmlSearch(firstPageXml,
>              
>"/shell/page[1]//[EMAIL PROTECTED]'#SECTION_NAME#']");
>aryDetails = aryDetails[1]; //just for convenience tempElem = 
>XmlElemNew(attributes.xmlDoc, "myelemname"); 
>tempElem.attributes = aryDetails.attributes; 
>tempElem.xmlchildren = aryDetails.xmlchildren; 
>tempElem.xmlText = aryDetails.xmlText; 
>ArrayInsertAt(attributes.xmlDoc.XmlRoot.XmlChildren[1].XmlChildren,
>              1, 
>              tempElem);
></cfscript>
>
>This is totally untested - but may work ;o)
>
>Mark
>
>------------------------------------------------------------------
>[EMAIL PROTECTED]
>ICQ: 3094740
>Safe From Bees
>[ www.safefrombees.com ]
>
>
>Quoting Gavo <[EMAIL PROTECTED]>:
>
>> Hello, Can anyone tell me why I am getting an error when i am 
>> extracting a node from one xml document and insert it into 
>another the 
>> code is as follows
>> 
>> <cfset aryDetails =
>> 
>xmlSearch(firstPageXml,"/shell/page[1]//[EMAIL PROTECTED]'#SECTIO
>> N_NAME
>> #']") >
>> <cfset ArrayInsertAt( 
>> attributes.xmlDoc.XmlRoot.XmlChildren[1].XmlChildren,
>> 1, aryDetails[1])>
>> 
>> If I do the same with the same xml document it doesnt error. I have 
>> been trying to figure this out for a while now and its starting to 
>> drive me crazy!!!
>> 
>> The error is as follows:-
>> 
>> WRONG_DOCUMENT_ERR: That node doesn't belong in this document.
>> 
>> Any help would be appreciated!
>> 
>> 
>
>---
>You are currently subscribed to cfaussie as: 
>[EMAIL PROTECTED] To unsubscribe send a blank email to 
>[EMAIL PROTECTED]
>
>MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia 
>http://www.mxdu.com/ + 24-25 February, 2004


---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004

Reply via email to