我有一個XPath查詢我在PHP運行鍼對下面的XML從CWE:如何在PHP中使用XPATH打印子節點的特定內容?
<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>
我寫了下面的PHP使用XPath以目標的「Description_Summary」子節點中的內容,但是,它只是返回Array()。我有一個$ _GET,它從前一頁拉出$ searchString變量,指向我在「弱點」節點中找到的特定屬性。
什麼它目前返回:
Array
(
[0] => SimpleXMLElement Object
(
)
)
什麼是錯我的print語句或XPath查詢?謝謝!
這是一個錯字:'Description/Description_Text/text()'?你是否想要使用'Description/Description_Summary/text()'? – Joe
是的,謝謝喬,這是一個錯字。我會糾正這一點。 – user1995565
你的xpath查詢看起來很好,你確定你的$ searchString是'Test'。 – Desu