I've hunted around for a solution to this but haven't found a simple
or clean one (maybe there isn't one) but maybe someone here has some
suggestions.
I have two XML objects and I want to take an XML node from one and
insert it into the other
XML Object 1:
<?xml version="1.0" encoding="UTF-8"?>
<styles>
<style>
<property>background</property>
<value>#FFFFFF</value>
</style>
</styles
XML Object 2:
<?xml version="1.0" encoding="UTF-8"?>
<styles>
<style>
<property>border-color</property>
<value>#00A0AF</value>
</style>
</styles>
I want to take the <style> node in XML Object 2 and add/insert it into
XML Object 1 so I end up with this result:
<?xml version="1.0" encoding="UTF-8"?>
<styles>
<style>
<property>background</property>
<value>#FFFFFF</value>
</style>
<style>
<property>border-color</property>
<value>#00A0AF</value>
</style>
</styles>
You can't do a direct assignment like this:
<cfset
arrayAppend(xmlObj1.styles.XMLChildren,xmlObj2.styles.XMLChildren[1])>
as it complains with the message:WRONG_DOCUMENT_ERR: A node is used in
a different document than the one that created it.
There doesn't seem to be any simple examples on how to use
XmLElemNew() to create a copy of a node easily it looks like you'd
have to manually iterate through the element attributes and set them.
Thanks
Barry
Ben Nadel has some nice tools:
http://www.bennadel.com/blog/1532-Copy-Import-XML-Nodes-Into-A-ColdFusion-XML-Document.htm
we grabbed a bunch of his XML tools and other stuff we found and put
them in a XML utility CFC, it gets used lots :-)
--
Yours,
Kym Kovan
mbcomms.net.au
On Mar 4, 11:49 am, Kym Kovan <dev-li...@mbcomms.net.au> wrote:
> On 4/03/2010 07:17, BarryC wrote:
>
> > Hi,
>
> > I've hunted around for a solution to this but haven't found a simple
> > or clean one (maybe there isn't one) but maybe someone here has some
> > suggestions.
>
> > I have two XML objects and I want to take an XML node from one and
> > insert it into the other
>
> Ben Nadel has some nice tools:
>
> http://www.bennadel.com/blog/1532-Copy-Import-XML-Nodes-Into-A-ColdFu...