<?php $doc = new DOMDocument(); //$doc->loadXML($xml); $doc->load('book.xml'); $xpath = new DOMXPath($doc); $query = "//book[@id = '2']"; $entries = $xpath->query($query); foreach ($entries as $entry) { echo "节点 ". $entry->nodeName; for($i=1; $i<$entry->childNodes->length; $i+=2) { $testNode = $entry->childNodes->item($i); echo "<br />节点 ".$testNode->nodeName; echo "<br />内容 ".$testNode->nodeValue; } } ?>
http://bbs.csdn.net/topics/330029501