下面的代码应该打印:PHP XPath Example,但它没有。我不确定为什么。
文章.xml:
<?xml version="1.0" encoding="UTF-8"?>
<articles>
<article id="1">
<tags>
<tag>php</tag>
<tag>xpath</tag>
</tags>
<title>PHP XPath Example</title>
</article>
<article id="2">
<tags>
<tag>dom</tag>
<tag>dodocument</tag>
</tags>
<title>DomDocument Tutorial</title>
</article>
</articles>
测试.php:
<?php
require 'krumo/class.krumo.php';
//phpinfo();
$file = "/home/veronzhg/public_html/venturelateral.com/pi_candidate_project/articles.xml";
$xml = simplexml_load_file($file);
krumo($xml);
$arts = $xml->xpath("/articles/article/title");
krumo($arts);
foreach ($arts as $art)
{
echo $art->textContent ." printed <br />";
//nodeValue
}