Reputation:
I'm currently having trouble with XMLParse()
, as the title says, it keeps throwing this error
An error occured while Parsing an XML document.
Content is not allowed in prolog.
My code is pretty basic at the moment, I'm just trying to get it to dump the XML values.
<cfset XMLPOST = GetHTTPRequestData().content>
<cfset xmlDOM = XMLParse(XMLPOST)>
<cfdump var="#xmlDOM#">
I've tried Ben Nadels method of determining whether it was a BOM or not, and his dump gave me this output
[x] - 120
[m] - 109
[l] - 108
[=] - 61
[%] - 37
[3] - 51
which seems to me like there isn't a problem with that character.
The XML is being posted to our server so I wonder if it that causing the problem? The XML which is being posted is in this format
xml=%3Cjob%3E%0D%0A++++%3Cjobref%3EExample+jobref%3C%2Fjobref%3E%0D%0A++++%3Cjobtitle%3EExample+jobtitle%3C%2Fjobtitle%3E%0D%0A++++%3Cdescription%3EExample+description%3C%2Fdescription%3E%0D%0A%3Cjob%3E%0D%0A++++++++++++
I have a feeling that it is this which is causing the errors? When I manually specify this XML on my document as a variable in its original form
<job>
<jobref>Example jobref</jobref>
<jobtitle>Example jobtitle</jobtitle>
<description>Example description</description>
<job>
and parse that variable, it dumps fine.
I assume that what I will need to do is change the XML Post format to a different format before I try to parse it? I have tried to use ToString()
but to no avail.
Thanks!
Upvotes: 2
Views: 4175
Reputation: 15587
Instead of using the raw content of the request you should use ColdFusion's FORM-Scope which will handle URLdecode etc. for you and splits up the body to seperate variables:
Replace:
<cfset XMLPOST = GetHTTPRequestData().content>
<cfset xmlDOM = XMLParse(XMLPOST)>
<cfdump var="#xmlDOM#">
With:
<cfset XMLPOST = FORM.xml>
<cfdump var="#XMLParse(XMLPOST)#">
Maybe you'd also want to check if it's valid XML which is posted with isXML()
-function.
Upvotes: 2