Results 1 to 9 of 9

Thread: XML data feed reading problem

  1. #1

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    39

    Post 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&amp;subid=1&amp;offerid=40840.1&amp;type=10&amp;tmpid=977&amp;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!

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  3. #3
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    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.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: XML data feed reading problem

    Quote Originally Posted by Nightwalker83 View Post
    The doctype stuff shouldn't be in the xml file that still goes in the .php file.
    Completely wrong.

  5. #5
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: XML data feed reading problem

    Sorry to add a meaningless response, but +1 @penegate.

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: XML data feed reading problem

    Quote Originally Posted by penagate View Post
    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

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: XML data feed reading problem

    Quote Originally Posted by penagate View Post
    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

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width