Imoddedu Posted July 17, 2011 Share Posted July 17, 2011 Hey there! I have a problem when this parses XML...I get these errors:Notice: Trying to get property of non-object in . . .just use this as the feed: http://articlefeeds.nasdaq.com/nasdaq/symbols?symbol=GOOG <?php // Get ticker string and explode $searchstring = $_GET["ticksearch"]; $ticker = explode(":", $searchstring); // Find ticker news feed $tickerfeed = "http://articlefeeds.nasdaq.com/nasdaq/symbols?symbol=" . $ticker[0];?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><title></title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta content="IE=8" http-equiv="X-UA-Compatible"><meta name="keywords" content="" /><meta name="description" content="" /><link type="text/css" href="css/ui-lightness/jquery-ui-1.8.14.custom.css" rel="stylesheet" /><link type="text/css" href="style.css" rel="stylesheet" /><script type="text/javascript" src="js/jquery-1.5.1.min.js"></script><script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script></head><body><div id="tabs"> <ul> <li><a href="#tabs-1">Info</a></li> <li><a href="#tabs-2">News</a></li> </ul> <div id="tabs-1"> <form id="search" method="get" action="results.php"> <input id="searchbox" name="ticksearch" size="40" type="text" value="" /> <input id="searchbutton" value="Go" type="submit" /> </form> <br /> <b> <u> <?php echo $ticker[0]; ?> </u> </b> <?php echo " | "; echo $ticker[1]; ?> <br /> <br /> <?php // XML Parsing $xmlDoc = new DOMDocument();$xmlDoc->load($tickerfeed);//get elements from "<channel>"$channel=$xmlDoc->getElementsByTagName('channel')->item(0);$channel_title = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;$channel_link = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;$channel_desc = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;//get and output "<item>" elements$x=$xmlDoc->getElementsByTagName('item');for ($i=0; $i<=2; $i++) { $item_title=$x->item($i)->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $item_link=$x->item($i)->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $item_desc=$x->item($i)->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>"); echo ("<br />"); echo ($item_desc . "</p>"); }?> </div> <div id="tabs-2"> </div></div></body></html> Link to comment Share on other sites More sharing options...
Imoddedu Posted July 18, 2011 Author Share Posted July 18, 2011 Also: any reason why I only get that error with those two specific lines? ->item(0)->childNodes->item(0)->nodeValue;and this line right below it:->item(0)->childNodes->item(0)->nodeValue; Link to comment Share on other sites More sharing options...
Ingolme Posted July 18, 2011 Share Posted July 18, 2011 It means that one of those elements is not an object.Most likely one of the item(0) is undefined because there are no child nodes. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.