Jump to content

Parsing XML


Imoddedu
 Share

Recommended Posts

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>

Edited by Imoddedu
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...