Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

    $xmlDoc = new DOMDocument()- loading first 5 items help

    Hi all

    im having trouble with some code of mine
    PHP Code:
    <?php

     $xml
    =("http://www.amazon.co.uk/rss/new-releases/dvd/ref=pd_nr_rss_link");


    $xmlDoc = new DOMDocument();
    $xmlDoc->load($xml);

    for (
    $i 0$i 5$i++) {
    //get elements from "<channel>"
    $channel=$xmlDoc->getElementsByTagName('item')->item($i);
    $channel_title $channel->getElementsByTagName('title')->item($i)->childNodes->item(0)->nodeValue;

    echo 
    $channel_title;
    echo(
    "<br />");
    }
    ?>
    i get the first item title display but after that i get

    Notice: Trying to get property of non-object in C:\wamp\www\Website\testfeedamazon.php on line 12

    Fatal error: Call to a member function item() on a non-object in C:\wamp\www\Website\testfeedamazon.php on line 12

    not sure why thought...
    cheers

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    PHP Code:
    $channel_title $channel->getElementsByTagName('title')->item($i)->childNodes->item(0)->nodeValue
    Well, that doesn't make much sense. You are already inside the "item" node; there's only one "title" node there, so calling item($i) produces an error for all but the first node.

    Use
    PHP Code:
    $channel_title $channel->getElementsByTagName('title')->item(0)->nodeValue
    instead and it will work.

  • Users who have thanked venegal for this post:

    LJackson (05-04-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •