How to print element values when iterating through XML document in PHP
- by pharma_joe
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!