PDA

View Full Version : getting xml datas



eilijah
5 Oct 2011, 7:03 AM
Hello,

I tried to get the datas from a xml file locally with this code :
http://pastebin.com/dr9LBty5

But i get this error :
"Uncaught TypeError: Object #<Object> has no method 'read'"
I did include the app.js file into the index.html.

I tried too with the similar code and a scripttap type in place of the ajax one.
I get the following error :
"Resource interpreted as Script but transferred with MIME type application/rss+xml."
But i can see that the request response is containing the xml datas. I tried too with a remote serveur and i got the same behaviour.

So first i am wondering about this 'read' issue and secondly i was wondering if there was a way to get some xml datas with the 'scripttag' type.

eilijah
10 Oct 2011, 10:27 AM
Ok finally i used a litle php proxy on my server.

I started from the following php script : https://raw.github.com/cowboy/php-simple-proxy/master/ba-simple-proxy.php.

With a request like :

myserver/ba-simple-proxy.php?url=http://example.com/thepageiwant.anyformat

You can get "thepageiwant.anyformat" then getting back in a JSON object. The page is just emedded in a string, u got something like :

{ "contents": "<html>...</html>"}

If you want to get a xml file you can use a xml to json converter like this one : http://www.ibm.com/developerworks/xml/library/x-xml2jsonphp/

You have just to include the class into the proxy and convert $data line 248 :

$json = json_encode( $data );
->

$json = json_encode( xml2json::transformXmlStringToJson($data) );

Then you get back a full json object with your data.

Of course it's a basic set, you should adapt it as you want.

cheers

SOLVED