tags:

views:

100

answers:

1

I am iterating through the results of a service call to yahoo news thus:

    //Send service request
    if (!$yahooResults = file_get_contents($yahooRequest)) {
      echo 'Error processing service request';
    }

    //Read result into xml document
    $yahooResultXml = new DOMDocument('1.0', 'UTF-8');
    $yahooResultXml->loadXML($yahooResults);

    //Build page
    include_once('components/pageHeader.php');
    echo 'Search Results';
    //echo $yahooResultXml->saveHTML();
    //Iterate over each Result node
    $stories = $yahooResultXml->getElementsByTagName('Result');
    foreach ($stories as $story) {
      //Title
      //Summary
      //Url
      //Source
      //Language
      //Publish Date
      //Modification Date
    }

    include_once('components/pageFooter.php');

Each Title is in a Title node within a Result Node. I cannot figure out how to simply echo the content of the Title node!

A: 

Check the first user comment at PHP: DOMDocument::getElementsByTagName

$items = $doc->getElementsByTagName('item'); $headlines = array();

foreach($items as $item) { 
    $headline = array(); 

    if($item->childNodes->length) { 
        foreach($item->childNodes as $i) { 
            $headline[$i->nodeName] =

$i->nodeValue; } }

    $headlines[] = $headline; 
}
Indrek