House of Fusion
Home of the ColdFusion Community

Search cf-talk

October 08, 2008

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Subscribe Now
Fusion Authority Quarterly Update - ColdFusion 8 Special Edition
Search over 2,500 ColdFusion resources here  >>>      
Home /  Groups /  ColdFusion Talk (CF-Talk)

Dynamic XML(DOM)

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
LSD 4Me
07/08/2008 02:06 PM

Hi I am currenlty using a form to search for dates in a remote database. The results are returned directly in the browser in XML format. I need to setup a way to have that xml data returned dynamicaly to a page which will then give me the ability to manipulate the data returned (either display in html form or insert into a local db) We are on CF8 and im like a deer in headlights when it comes to xml. does anybody know a good starting point? Ive researched plenty but ALL the examples require an xml file to already exist on not be generated dynamically. Any help is appreciated! THanks!!

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Brad Wood
07/08/2008 02:28 PM

I'm not sure what you mean by " results are returned directly in the browser in XML format", but I'll ignore that for now and assume you are calling some webservice, or cfhttping to a URL. Have the administrators of the "remote database" provided you with an XSD or DTD which lets you know what the XML will look like? As long as the format of the XML (what tags and attributes there are) is predictable, it doesn't really matter whether or not you are using XML that was created dynamically or read from a static file-- your code will work the same way. ColdFusion has some VERY handy ways to deal with XML, but it may help you to think of ColdFusion's representation of an XML object as an array of structs. I don't know how you are receiving the XML, but for example, it it was in a string variable called "my_xml_string_variable", all you need to do is: <cfset xml_doc = xmlparse(my_xml_string_variable)> <cfdump var="#xml_doc#"> That should at least get you started. ~Brad Hi I am currenlty using a form to search for dates in a remote database. The results are returned directly in the browser in XML format. I need to setup a way to have that xml data returned dynamicaly to a page which will then give me the ability to manipulate the data returned (either display in html form or insert into a local db) We are on CF8 and im like a deer in headlights when it comes to xml. does anybody know a good starting point? Ive researched plenty but ALL the examples require an xml file to already exist on not be generated dynamically. Any help is appreciated! THanks!!

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dominic Watson
07/08/2008 02:35 PM

----- Excess quoted text cut - see Original Post for more ----- Or, if you have an URL that outputs the XML, you can do: <cfset xml_doc = xmlparse("http://www.myxmloutput.com/?foo=bar&l=45")>; <cfdump var="#xml_doc#"> ColdFusion will recognise that you are passing the parser an URL and request the output of it as its XML input. Pretty handy really! HTH Dominic -- Blog it up: http://fusion.dominicwatson.co.uk

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
LSD 4Me
07/08/2008 02:41 PM

Dominic, The remote webservice requires data to be POSTed to it and will not accept GET. Will the xmlparse work with POST requests?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dominic Watson
07/08/2008 02:49 PM

No it won't. For that, your best bet is to use cfhttp to post the data and store the resultant output as a variable: <cfhttp url="http://myurl.com" method="POST">    <cfhttpparam ...> </cfhttp> <cfset xmlContent = cfhttp.fileContent> <cfset xml_doc = xmlparse(cfhttp.filecontent)> <cfdump var="#xml_doc#"> I'm not sure of the cfhttp syntax off the top of my head (don't copy and paste that) but that should get you started on the right path. HTH Dominic > Dominic, > > The remote webservice requires data to be POSTed to it and will not accept GET. Will the xmlparse work with POST requests?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dominic Watson
07/08/2008 02:50 PM

Oops, my code shoulda looked like: <cfhttp url="http://myurl.com" method="POST">    <cfhttpparam ...> </cfhttp> <cfset xml_doc = xmlparse(cfhttp.filecontent)> <cfdump var="#xml_doc#"> Dominic -- Blog it up: http://fusion.dominicwatson.co.uk

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
LSD 4Me
07/08/2008 03:01 PM

Dominic!!!! You the man. Thats exactly what i neeeded. Now that I can have the data parsed I can manipulate it. THANK YOU SO MUCH!!!!!

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
LSD 4Me
07/08/2008 02:38 PM

"...I don't know how you are receiving the XML, but for example, it it was in a string variable called "my_xml_string_variable", all you need to do is:" This is where the confusion is. I am not sure how to parse the XML data that is returned into a variable. You are correct in that the XML is returned from a remote web service. What i am trying to do is take the results, put them into an array and then more likely than not insert it into a local DB.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Brad Wood
07/08/2008 02:50 PM

Did you read my post?  I explained how to parse the xml data.  It was the part of the code that used the xmlparse() function. (Imagine that!) :) When you say XML data, you're not referring to a SOAP packet are you? Perhaps you could post your code that calls the web service so we could get a better handle on what you are doing. ~Bard "...I don't know how you are receiving the XML, but for example, it it was in a string variable called "my_xml_string_variable", all you need to do is:" This is where the confusion is. I am not sure how to parse the XML data that is returned into a variable. You are correct in that the XML is returned from a remote web service. What i am trying to do is take the results, put them into an array and then more likely than not insert it into a local DB.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
LSD 4Me
07/08/2008 02:56 PM

"...When you say XML data, you're not referring to a SOAP packet are you?" Yes, it is a SOAP packet returned in XML format. The API that was written for the remote webservice has plenty of SOAP related requests but we are using the HTTP POST method insteatd of creating a full blown API on our side.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Brad Wood
07/08/2008 03:08 PM

Well, heck-- you're making this harder than it has to be.  You don't need a "full blown API"-- ColdFusion does all the SOAP nonsense for you! If you are calling a SOAP web service, all you need is a couple lines of code.  Check out: http://livedocs.adobe.com/coldfusion/6/Developing_ColdFusion_MX_Applicat ions_with_CFML/webservices4.htm Two simple examples (copied from that page) would be: <cfinvoke   webservice = "http://www.xmethods.net/sd/2001/BabelFishService.wsdl"   method = "BabelFish"   translationmode = "en_es"   sourcedata = "Hello world, friend"   returnVariable = "foo"> <cfoutput>#foo#</cfoutput> Or... <cfscript>   ws = CreateObject("webservice",         "http://www.xmethods.net/sd/2001/BabelFishService.wsdl");   xlatstring = ws.BabelFish("en_es", "Hello world, friend");   writeoutput(xlatstring); </cfscript> All the SOAP stuff happens in the background and you get a regular ColdFusion variable back. I don't know what kind of variable your web service is returning (array, string, complex type, ect), but looking at the WSDL will tell you that. ~Brad "...When you say XML data, you're not referring to a SOAP packet are you?" Yes, it is a SOAP packet returned in XML format. The API that was written for the remote webservice has plenty of SOAP related requests but we are using the HTTP POST method insteatd of creating a full blown API on our side.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
LSD 4Me
07/08/2008 03:23 PM

Brad, This may work even better as this will probably allow for a better integration. I will start messing around with it now. THANKS!


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists