|
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Dynamic XML(DOM)
HiLSD 4Me 07/08/08 02:06 P I'm not sure what you mean by " results are returned directly in theBrad Wood 07/08/08 02:28 P > I don't know how you are receiving the XML, but for example, it it wasDominic Watson 07/08/08 02:35 P Dominic,LSD 4Me 07/08/08 02:41 P No it won't. For that, your best bet is to use cfhttp to post the dataDominic Watson 07/08/08 02:49 P Oops, my code shoulda looked like:Dominic Watson 07/08/08 02:50 P Dominic!!!!LSD 4Me 07/08/08 03:01 P "...I don't know how you are receiving the XML, but for example, it it wasLSD 4Me 07/08/08 02:38 P Did you read my post? I explained how to parse the xml data. It wasBrad Wood 07/08/08 02:50 P "...When you say XML data, you're not referring to a SOAP packet are you?"LSD 4Me 07/08/08 02:56 P Well, heck-- you're making this harder than it has to be. You don'tBrad Wood 07/08/08 03:08 P Brad,LSD 4Me 07/08/08 03:23 P 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!! 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!! ----- 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 Dominic, The remote webservice requires data to be POSTed to it and will not accept GET. Will the xmlparse work with POST requests? 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? 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 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!!!!! "...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. 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. "...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. 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. Brad, This may work even better as this will probably allow for a better integration. I will start messing around with it now. THANKS!
|
Mailing Lists
|
Latest Fusion Authority Articles
|
||||||