You have two options here.  You can do it with undocumented ColdFusoin 
functionality that allows the copying and replacing of nodes in a CF XML object.

Or you can use XSLT code and the xmlTransform() function.  I generally prefer 
the latter.

Contact my off-list if you would like a copy of the below as a CFM file.

<cfxml variable="doc1">
<root>
        <member id="10">
                <name>Ian</name>
                <sex>male</sex>
        </member>
</root>
</cfxml>

<cfxml variable="doc2">
<root>
        <member id="1">
                <name>Joe</name>
                <sex>male</sex>
        </member>
        <member id="2">
                <name>John</name>
                <sex>male</sex>
        </member>
        <member id="3">
                <name>Sue</name>
                <sex>female</sex>
        </member>
</root>
</cfxml>

<cffile action="write" file="#expandPath("/")#\doc2.xml" 
output="#ToString(doc2)#" nameconflict="overwrite">

<!--- METHOD ONE using a depreciated and undocumented method --->
<cfset newNode = doc1.root.member.cloneNode(true)>
<cfset doc2.changeNodeOwner(newNode)>
<cfset doc2.root.appendChild(newNode)>

<cfdump var="#doc2#" label="Merged by hidden functions" expand="no">

<!--- METHOD TWO using XSLT --->
<!--- create an xsl docutment--->
<cfoutput>
<cfsavecontent variable="transformer">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
        <xsl:output method="xml"/>
        <!--load the merge file -->
        <xsl:variable name="emps" 
select="document('#expandPath("/")#\doc2.xml')"/>
        <!--- this line references and XML file to be combined with the main 
file, 
        I wonder if there is a way to use an XML document in memory here? --->
        
        <!-- combine the files -->
        <xsl:template match="/">
                <root>
                        <!-- select all the child nodes of the root tag in the 
main file -->
                        <xsl:for-each select="root/child::*">
                                <!-- copy the member tag -->
                                <xsl:copy-of select="."/>
                        </xsl:for-each>
                        
                        <!-- and all the child nodes of the root tag in the 
merge file -->
                        <xsl:for-each select="$emps/root/child::*">
                                <!-- copy the member tag -->
                                <xsl:copy-of select="."/>
                        </xsl:for-each>
                </root>
        </xsl:template>
</xsl:stylesheet>
</cfsavecontent>
</cfoutput>

<!--- create a combined xml document --->
<cfset doc2 = XMLparse(XMLtransform(doc1,transformer))>

<cfdump var="#doc2#" label="Merged by XSLT" expand="no">


--------------
Ian Skinner
Web Programmer
BloodSource
www.BloodSource.org
Sacramento, CA
 
"C code. C code run. Run code run. Please!"
- Cynthia Dunning

Confidentiality Notice:  This message including any
attachments is for the sole use of the intended
recipient(s) and may contain confidential and privileged
information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the
intended recipient, please contact the sender and
delete any copies of this message. 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:211381
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to