javascript - cURL loading cross-domain remote XML - how to read & format it? -


I am using the following to load a remote XML file stored on a different server.

   

And as you can see, the results are being stored in $ xml string.

I can display it in the brush using:

   

But I need to select and format certain parts of the data.

I know that this can be done, and how many posts I have posted it in XMLhttp and many other ways, but I do not find any specific method for my needs because my XML file is now mandatory The form is a PHP string.

I am following the same type of functionality, following the JS script (which will work just fine if the XML file is stored locally, but I do not do it because it does not work):

  & lt; Script & gt; If (window.XMLHttpRequest) {// code for IE7 +, Firefox, Chrome, Opera, Safari xmlhttp = New XMLHttpRequest (); } Else {// code for IE6, IE5 xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP"); } Xmlhttp.open ("GET", "http://pathtofile.com/data.xml", Incorrect); Xmlhttp.send (); XmlDoc = xmlhttp.responseXML; Document.write ("& lt; Table border = '1' & gt;"); Var x = xmlDoc.getElementsByTagName ("Event"); {Document.write ("& lt; tr> ") for (i = 0; i & lt; x.length; i ++); Document.write (x [i] .getElementsByTagName ("date") [0] .childNodes [0] .nodeValue); Document.write ("& lt; / td> gt; & lt; td & gt;"); Document.write (x [i] .getElementsByTagName ("name") [0] .childNodes [0] .nodeValue); Document.write ("& lt; / td> "); & Lt; / Script & gt; Can someone point me in the right direction or offer an example? I'm not sure how to call $ xml string to use this way.  

Cheers!

To parse your XML string and get node value, in a way DOMDocument Use square. To remove the example # 1, you should work with Example # 1. Events like this:

  & lt ;? Php $ dom = new DOMDocument; $ Dom- & gt; LoadXML ($ XML); $ Event = $ dom- & gt; GetElementsByTagName ('Event'); $ Rows = ''; Forex Currency ($ events $ event) {$ date = $ name = ';; Foreign currency ($ event-> childNodes $ as a child) {switch ($ child- & n ;; nodeName)} {case 'date': $ date = $ child- & gt; NodeValue; break; Case 'name': $ name = $ child-> Node valve; break; }} $ Rows = "& Lt; tr & gt; & lt; td & gt; $ {date} & lt; / td & gt; & lt; TD & gt; $ {name} & lt; / td & gt; & lt; / Tr & gt; "; } 'Test' echo $ Rows; ? & Gt;  

The second solution would be XSL:

Build templates for your needs and use the XSLTPRocessor class.


Comments