Read XML from a HTTP POST

I program scripts to read XML posts just every once-and-awhile, and although very simple, every-time I forget how to do it.

Let’s say that we receive a XML HTTP POST via this code:

<cfhttp url="http://yourdomain.com/xml.cfm" method="post">
<cfhttpparam type="XML" name="MyXML" value="#myxml#">
</cfhttp>

This is what you would use to read that POST:

<cfset xmlPOST = GetHTTPRequestData().content>
<cfset xmlDOM = XmlParse(xmlPOST)>

The key here is the GetHTTPRequestData().content. Notice how we do not use form.MyXML.

Now we can manipulate the XML data using standard dot notation such as xmlDOM.Content.Value.XMLText.

Advertisements