Monday, November 1, 2010

Need help with XML feed

Hey,


What I am trying to do is send a url request to multimaps which in
turn gives me a xml form which looks like:

<?xml version="1.0" encoding="UTF-8" ?>
- <Results xmlns="http://clients.multimap.com/API" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://
clients.multimap.com/API http://clients.multimap.com/Schema/geocode_1.2.xsd"
locationCount="1">
- <Location geocodeQuality="4" geocodeScore="1.000" zoomFactor="16">
- <Address>
<PostalCode></PostalCode>
<DisplayName></DisplayName>
<CountryCode></CountryCode>
</Address>
- <Point>
<Lat></Lat>
<Lon>-</Lon>
</Point>
</Location>
</Results>

What I would like to do is output the lat and lon tags into html, but
I am quite new to php and keep coming up against problems. If anyone
can point me in the right direction that would be great. So far I have
got:

<?php
function produce_XML_object_tree($raw_XML) {
libxml_use_internal_errors(true);
try {
$xmlTree = new SimpleXMLElement($raw_XML);
} catch (Exception $e) {
// Something went wrong.
$error_message = 'SimpleXMLElement threw an exception.';
foreach(libxml_get_errors() as $error_line) {
$error_message .= "\t" . $error_line->message;
}
trigger_error($error_message);
return false;
}
return $xmlTree;
}

$url = "http://developer.multimap.com/API/geocode/1.2/
OA10102712756649236?qs=
";
$postcode ="";
$fullurl = ($url. $postcode);
$xml_feed_url = $fullurl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xml_feed_url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml = curl_exec($ch);
curl_close($ch);
$feed = produce_XML_object_tree($xml);
$second_entry_title = $feed->point[0]->lat;
?>
<html>
<h3><?php echo $second_entry_title ?></h3>
</html>

Now I think I am mixing up how SimpleXML works, as I am getting a
"Trying to get property of non-object" with reference to <?php echo
$second_entry_title ?> any help would be greatly appriciated.

Rob

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: