Mega Code Archive

 
Categories / Php / XML
 

Return a list of nodes that can be examined one at the time in a foreach() loop

<?php $data = DOMDocument::load("http://yourdomain.org/data.xml"); $stories = $data->getElementsByTagName("story"); foreach($stories as $story) {   $titles = $story->getElementsByTagName("title");   foreach($titles as $title) {     echo $title->nodeValue . " - ";   }   $urls = $story->getElementsByTagName("url");   foreach($urls as $url) {     echo $url->nodeValue . "\n";   } } ?>