需要按名称指定一些节点。例如,它应该如何查找节点'命令'或根节点?
这是我写的
$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']]"
但是如果我往上面走-有两个节点' catalogeitem ',我得到一个xpath错误
根节点:/*
节点名称://*[local-name() = 'command']
或//command
(假设它们在正确的XML名称空间中)
https://www.w3.org/TR/xpath/function-local-name