I am working on a project at the moment, that runs from a xml feed from an outside source.
I want to be able to display the information from this source, and not only that ... store it into MySQL database on my site.
So far, I have been able to retreive the info, parse it, and echo it onto my page. But thats it so far ... and i'm stuck!
HERE IS SOME SAMPLE CODE
THE XML FEED
Code: Select all
Code:
<?xml version="1.0"?>
<FeedData>
<ReadyMadeDeals>
<RMD ref="11085">
<FullAddress>10 Test Street, NE3 33S</FullAddress>
<PropertyInfo>A 2 Bed property in excellent condition with a large rear garden and parking for 2 cars. UPVC windows throughout.</PropertyInfo>
</RMD>
</ReadyMadeDeals>
</FeedData>Code: Select all
Code:
<?php
$xml_file = "http://www.somesite.com/xmlfile.xml";
$xmlDoc = new DOMDocument();
$xmlDoc->preserveWhiteSpace = false; //ignore useless childNodes which are just blank space
$xmlDoc->load($xml_file);
$readyMadeDeal_nodes = $xmlDoc->getElementsByTagName('ReadyMadeDeals'); //all the nodes by name of 'ReadyMadeDeals'
//each $item in the loop will be one of the 'ReadyMadeDeal' nodes:
foreach ($readyMadeDeal_nodes as $item) {
foreach ($item->childNodes as $RMDnode) { //each $RMDnode will be one of the 'RMD' nodes
//get the 'ref' attribute of the RMD node, if desired
echo '<small>property listing id #'.$RMDnode->getAttribute('ref').'</small><br>';
//get the 'FullAddress' and 'PropertyInfo' nodes from the 'RMD' nodes' childNode's:
foreach ($RMDnode->childNodes as $RMDchild) {
switch($RMDchild->nodeName) {
case 'FullAddress':
echo '<h2 style="margin:0;">'.$RMDchild->nodeValue.'</h2>';
break;
case 'PropertyInfo':
echo '<p style="margin-top:0;"><i>'.$RMDchild->nodeValue.'</i></p>';
break;
}
}
}
}
?>Any help is much, much, much appreciated!
Thanks in advance.