PHP编程实战14-12






snoopy
brown
beagle cross
teddy
brown
tabby
jade
black
lab cross

THE_XML;

$xml_object = simplexml_load_string($xml);

$xml_object->registerXPathNamespace('cat', 'http://foobar.com/cat');
$xml_object->registerXPathNamespace('dog', 'http://foobar.com/dog');
$names = $xml_object->xpath("dog:name");

foreach ($names as $name) {
    print $name . "
"; } ?>

知识点

  • 执行XPath时,需要注册命名空间,然后将命名空间作为查询元素的前缀.

你可能感兴趣的:(PHP编程实战14-12)