loadXML($response) === false) { die('Parsing failed'); } // Now traverse the DOM with this function. // This traversal function is suitable for the Yahoo! Maps and // Search web services, and any other Yahoo! Web Services that // return the number of results as attributes in the root tag and // have no other attributes in the results. For other Yahoo! Web // Services, such as Flickr web services, this routine will // have to be altered. function xml_to_result($dom) { $root = $dom->firstChild; foreach($root->attributes as $attr) $res[$attr->name] = $attr->value; $node = $root->firstChild; $i = 0; while($node) { switch($node->nodeName) { case 'Result': $subnode = $node->firstChild; while($subnode) { $subnodes = $subnode->childNodes; foreach($subnodes as $n) { if($n->hasChildNodes()) { foreach($n->childNodes as $cn) $res[$i][$subnode->nodeName][$n->nodeName]=trim($cn->nodeValue); } else $res[$i][$subnode->nodeName]=trim($n->nodeValue); } $subnode = $subnode->nextSibling; } break; default: $res[$node->nodeName] = trim($node->nodeValue); $i--; break; } $i++; $node = $node->nextSibling; } return $res; } $res = xml_to_result($dom); echo '
';
print_r($res);
echo '
'; ?>