PHP Mysql Updated By XML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
warrior555
Forum Newbie
Posts: 1
Joined: Wed Mar 03, 2010 9:58 am

PHP Mysql Updated By XML

Post by warrior555 »

Hi guys (and gals),

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>
MY CODE TO DISPLAY XML FEED

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;
}
}
}
}
 
?>
What I need to do now is INSERT/UPDATE the database from this information.

Any help is much, much, much appreciated!

Thanks in advance.
Kurby
Forum Commoner
Posts: 63
Joined: Tue Feb 23, 2010 10:51 am

Re: PHP Mysql Updated By XML

Post by Kurby »

Post Reply