View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > XmlParse PreviousNext

XmlParse

Converts an XML document that is represented as a string variable into an XML document object.

An XML document object.

Conversion functions, Extensibility functions, XML functions

XmlParse(xmlString [, caseSensitive ] )

cfxml, IsXmlDoc, XmlChildPos, XmlChildPos, XmlFormat, XmlNew, XmlSearch, XmlTransform

ColdFusion MX: Added this function.

Parameter

Description

xmlString

An XML document object string

caseSensitive

  • yes: maintains the case of document elements and attributes
  • no. Default.

The caseSensitive attribute value determines whether identifiers whose characters are of varying case, but are otherwise the same, refer to different components. For example:

If the XML document is 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 code to create the XML document object:

<cfset myXMLDocument = XmlParse(cfhttp.fileContent)>

If the XML document is in a file, use the cffile tag to 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 encoding, use the cffile tag charset attribute to specify the file's character encoding. For example, if the file is encoded in UTF, specify charset="UTF-8".


Contents > CFML Reference > ColdFusion Functions > XmlParse PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


spage said on Sep 20, 2003 at 3:12 AM :
If the piece of XML begins with a Processing Instruction
(such as the standard <?xml version="1.0" encoding="UTF-8"?> preamble),
CFMX 6.1 complains "XML declaration may only begin entities."

I think the workaround is to strip the processing instruction out using a regex.
spage said on Sep 20, 2003 at 3:23 AM :
My mistake, I thought I was running into the problem that <cfxml> has with PI's.

It turns out I had several blank lines at the beginning of my XML string, enough to confuse the parser. So if you get
"coldfusion.xml.XmlProcessException: XML declaration may only begin entities.", try putting a trim() around the XML content.
SeanCorfield said on Oct 28, 2003 at 3:24 PM :
xmlParse() seems to honor the DOCTYPE SYSTEM "blah.dtd"
directive but requires that the "blah.dtd" be a fully-qualified URI (either
file:/full/path/to/blah.dtd or http://server/path/to/blah.dtd).

It isn't clear from the docs here whether xmlParse() validates the XML
against the DTD or not.

It also isn't clear how xmlParse() treats the XSD schema equivalent
directives - again, does it actually validate the XML?
Der Nickname said on Dec 13, 2004 at 12:34 AM :
If I uses someting like this:
<cfscript>
xmlfile = xmlparse("#currentdirectory#/xmltemp.xml");
.
.
.
</cfscript>
It returns an error about a "missing document root object" (maybe an element. I'm working on an german server so I don't really know the english expression of this error).
It's the first time I tried to parse XML, and don't really know what's ment in this case.
Der Nickname said on Dec 13, 2004 at 5:58 AM :
Now it works without Quotationmarks. but My next Problem is to filter all these "Ü" e.g. (must be a Ü = &Uuml;) Its not possible tu filter it out, whereas it works with low case letters. Im using
REreplace(text,"Ü", "&Uuml;","ALL") (Thats just an exaple.) in the parser. but, when Im looking to the XML-File itself, it seems that all letters are written correctly to the file. Why does the parser translate them into something cryptical?
When I trie to change the letters in the script that writes my XML-File it returns an Error, like "Wrong Entity '&Uuml;'" and stops writing. Why?

My XML is set as UTF-8, does that matter anyhow?
No screen name said on Mar 11, 2005 at 1:32 AM :
I am currently having the same problem.
In my xml file is written "prénom" but it shows "prénom" after the parsing...
Anybody knows which parameter has to be set to solve this problem?

Michaël
No screen name said on Apr 26, 2005 at 6:09 PM :
Michael, maybe you should change the encoding.
DaveF67 said on Jul 6, 2005 at 9:22 AM :
ON SOLARIS THIS DOES NOT WORK... it does work on windows though...


Error Occurred While Processing Request
An error occured while Parsing an XML document.
Content is not allowed in prolog.




<CFHTTP METHOD="GET" URL="http://rss.news.yahoo.com/rss/tech/">
<CFSET tmpObj = trim(cfhttp.filecontent)>
<CFSET objRSS = xmlParse(tmpObj)>
DaveF67 said on Jul 6, 2005 at 9:33 AM :
DOH.... after adding a DUMP to the above, I get "CONNECTION FAILURE"

my bad...
jmk4444 said on Aug 3, 2005 at 9:09 AM :
I am trying to invoke a web service that returns a complex XML document string.,

I try to do the following:
<cfinvoke
webservice="http://www.domain.nett/portal/eig/services/assignment?wsdl"
method="getAssignmentCount"
returnvariable="aAssignmentsType">
<cfinvokeargument name="userID" value="userid"/>
<cfinvokeargument name="userPassword" value="password"/>
</cfinvoke>
<cfset mydoc = XmlParse(aAssignmentsType)>
<cfdump var="#mydoc#">

And I get the following:
An error occured while Parsing an XML document.
Content is not allowed in prolog.

I am brand new to this stuff, please help me understand what is incorrect?
No screen name said on Aug 8, 2005 at 4:55 PM :
Change this
<cfset mydoc = XmlParse(aAssignmentsType)>
to
<cfset mydoc = XmlParse(#aAssignmentsType#)>
Corey Gilmore said on Sep 16, 2005 at 1:25 PM :
Since the parser in 6.x seems to be utterly retarded, odds are high that you will need to manipulate the content a bit before calling XMLParse. If your XML is valid and you receive an error "Document root element is missing" then you need to remove the BOM from the data stream.
A nice description can be found at http://www.illequipped.com/blog/index.cfm?mode=entry&entry=45728590-3048-71C2-1791E325F79A4F50

Basically retrieve the document using CFHTTP. Find the beginning of the document using Find, and step back one position. Remove the first character (byte order mark) and then run XMLParse on the result.

XMLParse in CFMX 7 is greatly improved.

<cfset xmlDocName="http://#HTTP_HOST##Replace(SCRIPT_NAME, ListLast(SCRIPT_NAME, "/"), "")#somefile.xml">
<cfhttp url="#xmlDocName#" method="get" resolveurl="No"></cfhttp>
<cfset begin = Find("<rootElem>",CFHTTP.FileContent)>
<cfscript>begin = begin -1;
xmlDoc = RemoveChars(CFHTTP.FileContent,1,begin);xmlDoc = XMLParse(xmlDoc);
</cfscript>
<cfset xmlItems = XMLSearch(xmlDoc, "/rootElem/obj")>

Assuming somefile.xml looks like:
<rootElem><obj></obj><obj></obj></rootElem>
John2 said on Sep 22, 2005 at 4:04 AM :
some code that works fine locally on standard cfmx 7 doesnt work live on enterpirse using jrun.. I get this error.. any ideas??

An error occured while Parsing an XML document.
Content is not allowed in prolog.

133 : <cfset fileContent = xmlparse(#cfhttp.fileContent#)>
halL said on Sep 19, 2006 at 8:44 AM :
The following was pointed out by
hr_synq. We have edited it to fix a typo.

Content is not allowed in Prolog
Means no data in front of "<?xml version"
no characters, no spaces and no carridge return.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/funca125.htm