-
Notifications
You must be signed in to change notification settings - Fork 0
/
haitiLocationXmlConversion.php
executable file
·45 lines (39 loc) · 1.6 KB
/
haitiLocationXmlConversion.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
$catId = 45;
if(array_key_exists("id", $_GET))
{
$catId = $_GET["id"];
}
$url = "http://haiti.ushahidi.com/api?task=incidents&by=catid&resp=xml&id=" . $catId;
$handle = fopen($url,"rb");
$xmlFromUshahidi = stream_get_contents($handle);
fclose($handle);
$inputXml = simplexml_load_string($xmlFromUshahidi);
$outputXml = new SimpleXMLElement('<?xml version="1.0" ?><osm version="0.6"></osm>');
foreach($inputXml->payload->incidents->incident as $incident)
{
$node = $outputXml->addChild('node');
$node->addAttribute('id', '-1');
$node->addAttribute('lat', $incident->location->latitude);
$node->addAttribute('lon', $incident->location->longitude);
$tag = $node->addChild('tag');
$tag->addAttribute('k','title');
$tag->addAttribute('v',$incident->title);
$tag = $node->addChild('tag');
$tag->addAttribute('k','description');
$tag->addAttribute('v',$incident->description);
$tag = $node->addChild('tag');
$tag->addAttribute('k','date');
$tag->addAttribute('v',$incident->date);
$tag = $node->addChild('tag');
$tag->addAttribute('k','ushahidi:id');
$tag->addAttribute('v', $incident->id);
if (!empty($incident->location->name))
{
$tag = $node->addChild('tag');
$tag->addAttribute('k','locationName');
$tag->addAttribute('v',$incident->location->name);
}
}
print_r($outputXml->asXML());
?>