XML:
<?xml version="1.0" encoding="UTF-8"?>
<contacts>
<contact>
<name>Adrian Lynch</name>
<numbers>
<number type="mobile">3232323</number>
<number type="home">232323232</number>
</numbers>
</contact>
</contacts>
CF:
<cffile action="" variable="contactsFile"
file="#ExpandPath('.')#\contacts.xml">
<cfset VARIABLES.xmlContacts = XMLParse(contactsFile)>
<cfset VARIABLES.contacts = VARIABLES.xmlContacts.contacts.XmlChildren>
<!--- Store new contact position --->
<cfset VARIABLES.newContactPosition = ArrayLen(VARIABLES.contacts) + 1>
<!--- Add new contact element --->
<cfset VARIABLES.contacts[VARIABLES.newContactPosition] =
XmlElemNew(VARIABLES.xmlContacts, "contact")>
<cfset VARIABLES.newContact =
VARIABLES.contacts[VARIABLES.newContactPosition]>
<cfdump var="#VARIABLES.contacts#">
You should end up with a new contact element in the dump, writing it to file
should be this...
<cffile action="" file="#ExpandPath('.')#\contacts.xml"
output="#ToString(xmlContacts)#">
Let us know how you get on.
Ade
-----Original Message-----
From: Ian Skinner [mailto:[EMAIL PROTECTED]
Sent: 02 September 2004 19:10
To: CF-Talk
Subject: XML parsing in ColdFusion
I have two similar XML structures. I want to append a node from one
structure to the other. Can somebody point out to me how I would do this in
ColdFusion? I am apparently not getting the concept.
xmlDoc1 =
<root>
<member>
<memberchild1>
...
<memberchildN>
</member>
</root>
xmlDoc2 =
<root>
<member>
<memberchild1>
...
<memberchildN>
</member>
<member>
<memberchild1>
...
<memberchildN>
</member>
<member>
<memberchild1>
...
<memberchildN>
</member>
</root>
I want to append the member node from xmlDoc1 to the end of the member nodes
of xmlDoc2. Everything I try creates strange unfamiliar errors with
messages like "that node doesn't belong in this document" and "you have
tried to cast a variable in a way it wasn't meant to be used."
Thanks
--------------
Ian Skinner
Web Programmer
BloodSource
<file:///C:\Documents%20and%20Settings\iskinner\Application%20Data\Microsoft
\Signatures\www.BloodSource.org> www.BloodSource.org
<http://www.BloodSource.orgSacramento>
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.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

