HOME       >>       Programming

Xml Load() Problem Validating the length of array.


Can't seem to figure out this small problem, so I thought I'd send it out to kS to see what I'm not thinking of.


Here are the steps I have taken thus far:

Created an RSS feed

Designed a multipurpose feed reader that will pull data from the RSS feed

Using load() and getElementsByTagName("item") to pull in the data

Part of the reader's parameters are the number of rows to display

There's only one problem...when there are no results to display, it comes up with an error. The simple solution should be to either determine if the first value for the array exists or is blank. Either way, I can't seem to get the array correct no matter how much I try. I've attempted count() and sizeof(), but both return "1", and the error only arises after I try to read from the array using the getElementsByTagName(), so both are a "big help".


Maybe it's late...maybe I'm not thinking straight. Whatever the case, I needed to get connected with you guys again since the shoutbox (or its replacement) is not back online yet.


I'm pasting the code and error below:

2 $rssFile = new DOMDocument();3 $rssFile->load("./rss/?id=" . $feedID);45 //get and output "<item>" elements6 $item=$rssFile->getElementsByTagName("item");7 $y=0;8 if($feedCount>count($item)+1) $feedCount = count($item)+1;9 if(isset($item->item(0)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue))10 {11 for ($i=$feedStart-1; $i<=$feedCount-1; $i++)12 {15 $item_title=$item->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;16 $item_link=$item->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;17 $item_desc=$item->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;

Fatal error: Cannot use object of type DOMNodeList as array in C:\wamp\www\jl-ectronics\resources\php\feedreader01.php on line 9


Nevermind...I found the $item->length parameter after a lot of searching.


Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.