我试图使用DomXPath的方法。但我收到了奇怪的结果:
$xpath = new DomXPath($dom);
$result = $xpath->query('//students/group/student/name["sid"]');
foreach ($result as $node) {
echo "<", $node->tagName, "> : ", $node->nodeValue, "\n";
if ( $node->nodeValue == "sid"){
echo $node->nodeValue;
break;
}
}
为什么过滤条件不起作用?
答案 0 :(得分:1)
您的xml包含空间arount节点值。要比较它们只需删除那些空格:
if ( trim($node->nodeValue) == "sid") {