Jump to content

Updating MySQL Using XML?


justlukeyou

Recommended Posts

Hi,

 

Apologies to keep going on about this but I have hit a brick wall over updating my database with XML.  I have spent around 100 hours on this and so far I can only copy the file, I am unable so far to update my database with the information from the XML file.  I would be very grateful for any help you can offer to fix this. 

 

 

----Code so far---->

$xmlReader = new XMLReader();

$filename = "datafeed_98057.xml";
$url = "http://www.domain.co.uk/datafeed.xml";

file_put_contents($filename, file_get_contents($url));

$xmlReader->open($filename);

while ($xmlReader->read())

{

switch ($xmlReader->name)

{

case'prod':

$dom = new DOMDocument();
$domNode = $xmlReader->expand();
$element = $dom->appendChild($domNode);
$domString = utf8_encode($dom->saveXML($element));
$prod = new SimpleXMLElement($domString);

$id = $prod->prod['id'];
$description = $prod->name;
$image = $prod->awImage;
$fulldescription = $prod->desc;

//insert query
if(strlen($prod) > 0)

{
$query = mysql_query("REPLACE INTO productfeed
(id, description, fulldescription, image)
VALUES ('$id','$description','$image','$fulldescription') ");
echo $id . "has been inserted </br>";
}
else{echo ("This does not work </br>");}
}

 

This is an outline of the XML feed I am using, it only includes one item which I am using as a test:

 

- <merchant id="1829" name="Pinesolutions.co.uk">
- <prod id="39920873" pre_order="no" web_offer="no" in_stock="yes" hotPick="no" adult="no">
- <text lang="EN">
  <name>Oakleigh Wall Mirror 60x90</name> 
  <desc>Mirrors are useful anywhere in the house. Not only are they functional allowing you to see your reflection in order to look your best, they also add elegance to any room theyre placed in. We offer a variety of mirrors to fit your decorating tastes as well as wall space. The Oakleigh Wall Mirror radiates an elegant simplistic style, while offering a generous size glass. The Oakleigh Wall Mirror s frame is crafted from solid hardwood and is lacquered with a protective finish to guard against dust and unexpected stains. The Oakleigh Wall Mirror is versatile and can be hung portrait style at the top of a staircase or landscape. The Oakleigh Wall Mirrors light colour means it also complements all of the furniture in our Camden Painted Range because the range has ash tops. The Oakleigh Wall Mirror has fewer knots than traditional oak wood, but is built just as sturdy so you can be certain it will last you through the generations to come.</desc> 
  </text>
- <uri lang="EN">
  <awTrack>http://www.awin1.com/pclick.php?p=39920873&a=98057&m=1829</awTrack> 
  <awImage>http://images.productserve.com/preview/1829/39920873.jpg</awImage> 
  <mLink>http://www.pinesolutions.co.uk/bedroom-furniture/mirrors/wall-mirrors/oakleigh-wall-mirror-60x90/</mLink> 
  <mImage>http://media.pinesolutions.co.uk/images/products/903.333.3.4.jpg</mImage> 
  </uri>
- <price curr="GBP">
  <buynow>40.00</buynow> 
  </price>
- <cat>
  <awCatId>424</awCatId> 
  </cat>
  <brand /> 
  </prod>
  </merchant>

Link to comment
https://forums.phpfreaks.com/topic/229186-updating-mysql-using-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.