【发布时间】:2016-10-07 13:16:06
【问题描述】:
需要获取一些由名称指定的节点。例如它应该如何查找节点“命令”或根节点?
这是我写的
$xpath = "/ns0:StandardBusinessDocument/eanucc:message/eanucc:transaction/command";
$xpath .= "/eanucc:documentCommand/documentCommandOperand/ns1:catalogueItemNotification/catalogueItem";
$xpath .= "/catalogueItemChildItemLink/catalogueItem/catalogueItemChildItemLink/catalogueItem/tradeItem";
$xpath .= "/tradeItemIdentification/gtin[.='$gtin']/";
在哪里$gtin = 00000075032814
这就是我得到的
Array
(
[0] => SimpleXMLElement Object
(
[0] => 00000075032814
)
[1] => SimpleXMLElement Object
(
[0] => 00000075032814
)
)
UPD:事情是我可以得到这样的节点
"[catalogueItem/tradeItem/tradeItemIdentification/gtin[.='$gtin']]"
但如果我要往上走 - 还有两个节点“catalogueItem”,我会遇到 xpath 错误。
【问题讨论】:
-
你的问题不清楚。请将编程语言添加为标签,并显示可用于重现您的问题的完整代码示例。还显示输入的 XML 文档并说出您期望的结果。更多帮助:stackoverflow.com/help/mcve 和 stackoverflow.com/help/how-to-ask。