XML data feed reading problem
I am trying to read xml data feed using simple xml load api.
having problem with reading following XML format
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data SYSTEM "http://affiliates.mondera.com/affiliates/jewelry.dtd">
<data><description>birth_stone</description>
<date>9/7/2009 4:51:19 AM</date>
<row SKUid="3009776">
<SKU>3009776</SKU>
<WebLink>http://click.linksynergy.com/fs-bin/click?id=w7UOeEAmnJM&subid=1&offerid=40840.1&type=10&tmpid=977&RD_PARM1=http%3A%2F%2Fwww.mondera.com%2Fjewelry%2Fproduct.asp%3Fpartno%3D3009776</WebLink>
<ThumbNailImage>http://www.mondera.com/images/listimages/3009776.jpg</ThumbNailImage>
<LargeProductImage>http://www.mondera.com/images/large1/3009776.jpg</LargeProductImage>
<Price>200</Price>
<MainCategory>Gemstone Jewelry</MainCategory>
<Category>Earrings</Category>
<Short_Description>14k White Gold Sapphire Stud Earrings</Short_Description>
<Metal>14k White Gold</Metal>
</row>
</data>
Below is my code for google news feed
PHP Code:
<?php
$url = "http://news.google.com/?ned=us&topic=t&output=rss";
$rss = simplexml_load_file($url);
if($rss)
{
echo '<h1>'.$rss->channel->title.'</h1>';
echo '<li>'.$rss->channel->pubDate.'</li>';
$items = $rss->channel->item;
foreach($items as $item)
{
$title = $item->title;
$link = $item->link;
$published_on = $item->pubDate;
$description = $item->description;
echo '<h3><a href="'.$link.'">'.$title.'</a></h3>';
echo '<span>('.$published_on.')</span>';
echo '<p>'.$description.'</p>';
}
}
?>
Thanks in advance!
Re: XML data feed reading problem
The doctype stuff shouldn't be in the xml file that still goes in the .php file.
Re: XML data feed reading problem
The doctype is not a problem. The problem is that your PHP is looking for fields in the XML that exist in Google's RSS feed, but not in your XML file; it expects to find "channel," "title," "pubDate," etc., but your XML doesn't have these.
Use something like this...
Code:
<?php
$url = "myxml.xml";
$xml = simplexml_load_file($url);
if($xml)
{
echo '<h1>'.$xml->description.'</h1>';
echo '<li>'.$xml->date.'</li>';
$items = $xml->row;
foreach($items as $item)
{
$title = $item->SKU;
$link = $item->WebLink;
$description = $item->Short_Description;
echo '<h3><a href="'.$link.'">'.$title.'</a></h3>';
echo '<p>'.$description.'</p>';
}
}
?>
When you load in the XML, the $xml variable becomes the root node of your hierarchy (in this case, "data"). Then you can access your particular sub-nodes from there, as shown.
Re: XML data feed reading problem
Quote:
Originally Posted by
Nightwalker83
The doctype stuff shouldn't be in the xml file that still goes in the .php file.
Completely wrong.
Re: XML data feed reading problem
Sorry to add a meaningless response, but +1 @penegate.
Re: XML data feed reading problem
Quote:
Originally Posted by
penagate
Completely wrong.
Can you explain a bit more? I have never seen the doctype used within the xml file although I have only used xml with flash.
Re: XML data feed reading problem
So why make a statement like "doctype stuff shouldn't be in the xml file"?
Doctypes don't have anything to do with PHP, either, so instructing someone to put it into the PHP file is misleading.
A brief Google search will lead you to articles explaining about doctypes in XML. Perhaps you could have done that before posting an unhelpful response.
Re: XML data feed reading problem
Quote:
Originally Posted by
penagate
So why make a statement like "doctype stuff shouldn't be in the xml file"?
Doctypes don't have anything to do with PHP, either, so instructing someone to put it into the PHP file is misleading.
A brief Google search will lead you to articles explaining about doctypes in XML. Perhaps you could have done that before posting an unhelpful response.
I thought that it might need to go in there if there was html in that files as well.
Re: XML data feed reading problem
You can clearly see that is not a HTML or XHTML doctype of any sort.