How to print element values when iterating through XML document in PHP

Posted by pharma_joe on Stack Overflow See other posts from Stack Overflow or by pharma_joe
Published on 2010-05-13T07:31:02Z Indexed on 2010/05/13 7:34 UTC
Read the original article Hit count: 252

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about php

Related posts about Xml