User:Tagtheworld/PHP
SimpleXMLElement::xpath
I tried to extract some data from an .Osm File. -.-you can run a demo-command here at http://overpass-turbo.eu/
So I have something like this: [QUOTE]
"tags": { "addr:city": "Barcelona", "addr:housenumber": "1", "addr:postcode": "08022", "addr:street": "Carrer de Torras i Pujalt", "amenity": "hospital", "contact:email": "info@clinicasagradafamilia.com", "contact:fax": "+34 932124050", "contact:phone": "+34 932122300", "contact:website": "http://csf.com.es/", "name": "Cliníca Sagrada Família" }
[/QUOTE]
So, the question is this: how can store all those values I tried to make some kind of foreach without sucess. And definitely I don't know why is suposse we have one Iteration that get all the values and why is not possible to store together.
Well i heard about that we can use SimpleXMLElement::xpath here to get all the values and the corresponding values. For example : [CODE] $raw = <<<EOF <root> {
"type": "node", "id": 583257940, "lat": 41.4134446, "lon": 2.1426945, "tags": { "amenity": "hospital", "emergency": "yes", "name": "Clinica Delfos" }
}, {
"type": "node", "id": 618312181, "lat": 41.4138593, "lon": 2.1970778, "tags": { "addr:city": "Barcelona", "addr:housenumber": "211", "addr:postcode": "08020", "addr:street": "Carrer de Fluvià", "amenity": "hospital", "health_facility:type": "health_centre", "medical_system:western": "yes", "name": "CAP Sant Martí", "phone": "+93 307 07 66" }
}, {
"type": "node", "id": 876348001, "lat": 41.3841883, "lon": 2.1952253, "tags": { "amenity": "hospital", "emergency": "yes", "name": "Hospital del Mar", "website": "http://www.parcdesalutmar.cat/hospitals/hospital-del-mar/index.html", "wheelchair": "yes" }
},
</root> EOF; $xml = simplexml_load_string($raw);
foreach($xml->xpath("//way") AS $way){
$via = $way->xpath("tag[@k='name']/@v")[0]; foreach($way->nd AS $nd){ $idnode = $nd["ref"]; echo $idnode .", ". $via ."
"; }
}[/CODE]
how to use SimpleXMLElement::xpath here
btw - you can run a demo-command here at http://overpass-turbo.eu/
[CODE] /* This has been generated by the overpass-turbo wizard. The original search was: “hospital in rome”
- /
[out:json][timeout:25]; // fetch area “” to search in Template:GeocodeArea:rome->.searchArea; // gather results (
// query part for:rome “hospital” node["amenity"="hospital"](area.searchArea); way["amenity"="hospital"](area.searchArea); relation["amenity"="hospital"](area.searchArea);
); // print results out body; >; out skel qt;[/CODE]
then you get lots of results....
question: how to store those results in either excel or mysql?