Creating an XML document object from existing XML

The XmlParse function converts an XML document or document fragment represented as a text string into a ColdFusion document object.

If the XML document is already represented by a string variable, use the XmlParse tag directly on the variable. For example, if your application uses cfhttp action="get" to get the XML document, use the following line to create the XML document object:

<cfset myXMLDocument = XmlParse(cfhttp.fileContent)>

If the XML document is in a file, use cffile convert the file to a CFML variable, then use the XmlParse tag on the resulting variable. For example, if the XML document is in the file C:\temp\myxmldoc.xml, use the following code to convert the file to an XML document object:

<cffile action="read" file="C:\temp\myxmldoc.xml" variable="XMLFileText">
<cfset myXMLDocument=XmlParse(XMLFileText)>

Note: If the file is not encoded with the ASCII or Latin-1 character set, use the cffile tag charset attribute to specify the file's character set. For example, if the file is encoded in UTF, specify charset="UTF-8".

View comments on LiveDocs