Thankfully I stumbled across Taha Paksu's SimpleXML for PHP4 - you must join/login to download it, but it's worth it.
Once you have downloaded the ZIP file, place simplexml.class.php in your PHP 'app', and use the supplied example test.php to ensure everything is working:
<?which prints out a 'tree view' of the XML data.
require_once "simplexml.class.php";
echo "<pre>";
$file = "http://musicbrainz.org/ws/1/track/?query=metallica&type=xml";
$sxml = new simplexml;
$data = $sxml->xml_load_file($file);
print_r($data);
?>
If that works, you can then address individual elements (say your XML looks like this - an example from the download)
<?xml version="1.0" encoding="ISO-8859-1"?>then your PHP might look like this:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>
<format>text</format>
<content>Don't forget me this weekend!</content>
</body>
</note>
<?
require_once "simplexml.class.php";
$file = "http://SOMESERVER.com/example.xml";
$sxml = new simplexml;
$data = $sxml->xml_load_file($file);
?>
<html>
<body>
<table>
<td>to:</td><td><?php echo $data->to; ?></td>
<td>sender:</td><td><?php echo $data->from; ?></td>
<td>subject:</td><td><?php echo $data->heading; ?></td>
<td>message:</td><td><?php echo $data->body->content; ?></td>
</table>
</body>
</html>
You can read more in the SimpleXML for PHP4 forum... That's enough PHP for now - back to c#/t-sql/xaml/html/javascript... and hopefully soon MonoTouch!
Thanks mate! Took me a while to find this but worth the search!
ReplyDeleteInformative Blog
ReplyDeleteThanks for Sharing !!