我有一个 XPATH 查询,我在 PHP 中针对来自 CWE 的以下 XML 运行:
<Weaknesses>
<Weakness ID="211" Name="Test" Weakness_Abstraction="Base" Status="Incomplete">
<Description>
<Description_Summary>
The software performs an operation that triggers an external diagnostic or error message that is not directly generated by the software, such as an error generated by the programming language interpreter that the software uses. The error can contain sensitive system information.
</Description_Summary>
</Description>
</Weakness>
</Weaknesses>
我使用 XPATH 编写了以下 PHP,以便针对“Description_Summary”子节点中的内容,但是,它只是返回 Array()。我有一个 $_GET ,它从上一页中提取 $searchString 变量,指向我在“弱点”节点中找到的特定属性。
<?php
$searchString = $_GET["searchString"];
echo "<b>CWE Name: </b>" . $searchString . "</br>";
$xml = simplexml_load_file("cwe.xml");
$description = $xml->xpath('//Weakness[@Name="'. $searchString .'"]/Description/Description_Summary/text()');
echo "<pre>"; print_r($description); echo "</pre>";
?>
它目前返回的内容:
Array
(
[0] => SimpleXMLElement Object
(
)
)
我的打印语句或 XPATH 查询有什么问题?谢谢!