RE: Append Dom Document

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Date: Thu, 13 May 2010 18:49:35 -0600
Subject: Re:  Append Dom Document
From: quickshiftin@xxxxxxxxx
To: ajwei@xxxxxxxxxxxxx
CC: php-general@xxxxxxxxxxxxx



On Thu, May 13, 2010 at 5:46 PM, Alice Wei <ajwei@xxxxxxxxxxxxx> wrote:



Hi,



  I am trying to create a news feed page that loads a number of different feeds depending on what options the user selects. For some reason, I could not figure out how to get the dom document to "append" the different xml documents that get created.




Below is the code, and obviously now every time when I try to have a new item selected, then it displays that element's



<?php



$q=$_GET["q"];

$q2 = explode(" ",$q);

$count = count($q2);



for($i=0;$i<$count;$i++) {



//find out which feed was selected

  switch ($q2[$i]) {

    case "Weather":

        $xml=("http://rss.weather.com/rss/national/rss_nwf_rss.xml?cm_ven=NWF&cm_cat=rss&par=NWF_rss";);


        break;



    case "NFL":

      $xml = ("http://www.nfl.com/rss/rsslanding?searchString=home";);

      break;



    default:

        exit;

        break;

   }

}



$xmlDoc = new DOMDocument();

$xmlDoc->load($xml);



//get and output "<item>" elements

$x=$xmlDoc->getElementsByTagName('item');

for ($i=0; $i<=4; $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>");

  }

you might have an easier time w/ SimpleXML for this task; have a look at the examples:
http://us.php.net/manual/en/simplexml.examples-basic.php

the other thing i find strange about this code is the xml parsing assumes a similar schema when the source urls are from seemingly totally disparate domains, and topic .. id guess it sheer coincidence they have overlapping schemas at all.

I am not sure what you mean in your second point, but I can explain the first one. I am using PHP to parse RSS feeds, so that is why they all look the same. Or, what do you mean here? I checked out your example, but my problem here is that I cannot get the XML Dom document to append when I make a new selection. I am hoping that it would create a new sub document of some sort beneath the new one, instead of overwriting the entire document. 

Am I making sense here?

Alice 		 	   		  
_________________________________________________________________
The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail.
http://www.windowslive.com/campaign/thenewbusy?tile=multiaccount&ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux