\n"; echo " Node : " . $errorline['nodename'] . "
\n"; echo " Line : " . $errorline['line'] . "
\n"; echo " Column : " . $errorline['col'] . "
\n"; } die('XML parse error'); } // 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->document_element(); $res['totalResultsAvailable'] = $root->get_attribute('totalResultsAvailable'); $res['totalResultsReturned'] = $root->get_attribute('totalResultsReturned'); $res['firstResultPosition'] = $root->get_attribute('firstResultPosition'); $node = $root->first_child(); $i = 0; $k = null; while($node) { switch($node->tagname) { case 'Result': $subnode = $node->first_child(); while($subnode) { $subnodes = $subnode->child_nodes(); if(!empty($subnodes)) { foreach($subnodes as $k=>$n) { if(empty($n->tagname)) { $res[$i][$subnode->tagname] = trim($n->get_content()); } else { $res[$i][$subnode->tagname][$n->tagname]=trim($n->get_content()); } } } $subnode = $subnode->next_sibling(); } break; default: $res[$node->tagname] = trim($node->get_content()); $i--; break; } $i++; $node = $node->next_sibling(); } return $res; } $res = xml_to_result($dom); echo '
';
print_r($res);
echo '
'; ?>