Kobsondasusa
Kobsondasusa

Reputation: 25

Scraping data from php file

I am trying to get the car positions (if I can the cars state (gas, how clean, etc) from this site: https://carsharing.mvg-mobil.de/?ref=separate.

As far as I can tell they get their data from this URL:

https://carsharing.mvg-mobil.de/json/stations.php

Now I am having trouble converting that into usable XML format. I tried bringing it into String form by using

JSON.stringify() 

and go from there but that didn't seem to work. What im having trouble with are the { and quotation marks

Upvotes: 0

Views: 122

Answers (1)

Tanuel Mategi
Tanuel Mategi

Reputation: 1283

since your question is tagged as php, here is a simple code-snippet that will get you a xml-string:

<?php
//get json-string
$cars_json = file_get_contents("https://carsharing.mvg-mobil.de/json/stations.php");
//convert json to array
$cars_array = json_decode($cars_json,true);

//creat xml-object and fill recursive
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($cars_array, array ($xml, 'addChild'));

//create xml-string that can be saved
$cars_xmlstring = $xml->asXML();
echo $cars_xmlstring
?>

Upvotes: 2

Related Questions