|
-
Sep 9th, 2009, 02:03 AM
#1
Thread Starter
Member
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!
-
Sep 9th, 2009, 05:21 AM
#2
Re: XML data feed reading problem
The doctype stuff shouldn't be in the xml file that still goes in the .php file.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Sep 9th, 2009, 12:30 PM
#3
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.
-
Sep 9th, 2009, 10:31 PM
#4
Re: XML data feed reading problem
 Originally Posted by Nightwalker83
The doctype stuff shouldn't be in the xml file that still goes in the .php file.
Completely wrong.
-
Sep 10th, 2009, 04:46 AM
#5
Re: XML data feed reading problem
Sorry to add a meaningless response, but +1 @penegate.
-
Sep 10th, 2009, 07:35 PM
#6
Re: XML data feed reading problem
 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.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Sep 10th, 2009, 08:06 PM
#7
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.
-
Sep 10th, 2009, 10:43 PM
#8
Re: XML data feed reading problem
 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.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Sep 10th, 2009, 11:55 PM
#9
Re: XML data feed reading problem
You can clearly see that is not a HTML or XHTML doctype of any sort.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|