Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CF and XML?

Status
Not open for further replies.

GUJUm0deL

Programmer
Jan 16, 2001
3,676
US
I need some help intergrating XML into a CF application. Basicaly what I have to do is take records and submit them to a client via HTTP Post.

I queried the dB (the easiest part, lol). Now how can I incorporate XML into an CF application.

This is what I have so far:

Code:
<cfset fid = 1000>

<cfquery name="test" datasource="#some_DS#>
SELECT firstname, lastname, address, homenumber, city, zip, email
FROM Table1
WHERE fid = #fid#
</cfquery>

<cfhttp method="post" url="[URL unfurl="true"]http://www.somesite.com/someapplucation.aspx"[/URL] throwonerror="no">
???
???
???
???
???
</cfhttp>

What now?

The client gave this a "sample":
Code:
POST  HTTP/1.1
Host: soaptest.abc.123Test.com:80
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "[URL unfurl="true"]http://www.somesite.com/another_application"[/URL]

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/">[/URL]
 <soap:Body>
  <Info xmlns="[URL unfurl="true"]http://www.somesite.com/">[/URL]
   <ID>string</ID>
   <FirstName>string</FirstName>
   <LastName>string</LastName>
   <Email>string</Email>
   <StreetAddress>string</StreetAddress>
   <City>string</City>
   <ZipCode>string</ZipCode>
   <HomePhone>string</HomePhone>
  </Info>
 </soap:Body>
</soap:Envelope>

How can I incorporate the "sample" in CF? Any help is greatful.

Thanks.


____________________________________
Just Imagine.
 
im not big on XML but i think you would need to create your xml using the CFXML tag, then use CFHTTPPARAM type=XML to send the xml data. this is a very ugly example, but maybe it will give you some ideas, and btw i haven't tested this beyond the XML creation- i have nowhere to cfhttp it to.

Code:
<cfquery 
   name="GetParks" datasource="cfsnippets" 
   cachedwithin="#CreateTimeSpan(0, 0, 6, 0)#">
   SELECT PARKNAME, REGION, STATE
   FROM Parks
   ORDER BY ParkName, State
</cfquery>

<cfprocessingdirective suppresswhitespace="yes">
<cfxml variable="SendDoc" casesensitive="yes">
<SendDoc>
<cfoutput query="GetParks">
<ParkName>#XMLFormat(GetParks.PARKNAME)#</ParkName>
<Region>#XMLFormat(GetParks.REGION)#</Region>
<State>#XMLFormat(GetParks.STATE)#</State>
</cfoutput>
</SendDoc>
</cfxml>
</cfprocessingdirective>

<cfhttp method="post" url="[URL unfurl="true"]http://www.somesite.com/someapplucation.aspx"[/URL] throwonerror="no">
<cfhttpparam type="XML" value="#SendDoc#">
</cfhttp>

<cfdump var="#SendDoc#">
 
Thanks for responding. I forgot to mention that I also need to use SOAP to get the data across.

What I need to do is create a "handshake" first. I connect to the server (via SOAP) and get a ID, then when I get the ID I submit the data (in XML format). After I submit the data, I get a response from their system and log that in my dB.

I can do most of it, but how can I incorportae SOAP and XML into this application??

Any ideas is great. Thanks.


____________________________________
Just Imagine.
 
i dont think incorporating SOAP in the picture is too much different- something like this maybe:
Code:
<cfset SOAPaction="[URL unfurl="true"]http://URL_to_SOAP_Action">[/URL]

<!---Create the SOAP code as a variable--->
<cfsavecontent variable="xmlSOAPcontent">
<soap:Envelope xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/">[/URL]
<soap:Body>

[Body here in xml format]

</soap:Body>
</soap:Envelope>
</cfsavecontent>

<!--- Send Request --->
<cfhttp url="[URL unfurl="true"]http://FILENAME.wsdl"[/URL] method="POST" resolveurl="NO">

<cfhttpparam type="CGI" name="SOAPAction" value="#soapaction#">

<cfhttpparam type="xml" name="cgi" value="#xmlSOAPcontent#">

</cfhttp>
 
NorthStarDA, hmmmmm never thought about using CF vars for assignment of SOAP.

But there's another criteria before the actual data can be sent. See, first I have to create a "handshake" with the client's system. Then I get a STATUS for their system (if the STATUS is "valid" then I send the data over, if the status is "invalid" or "rejected" I log the reason in my dB.)

So, this is the way I thought of doing it:
Code:
<cfset ID = "">
<cfset Status = "">
<cfhttp url="someurls.com" throwonerror="no" resolveURL="yes">
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:soap="[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/">[/URL]
 <soap:Body>
  <Info xmlns="[URL unfurl="true"]http://www.somesite.com/">[/URL]
   <ID>#ID#</ID>
   <Status>#Status#</Status>
   <Zipcode>#Zip#</Zipcode>
  </Info>
 </soap:Body>
</soap:Envelope>
</cfhttp>

Then maybe I can use your mehtod to actually submit the data.


____________________________________
Just Imagine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top