2016-10-07 66 views
-1

需要获取由名称指定的某个节点。例如,它应该如何查找节点“命令”或根节点?如何通过xpath按名称获取根或指定节点?

这是我写的

 $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错误。

+0

你的问题不明确。请添加编程语言作为标记,并显示可用于重现问题的完整代码示例。同时显示输入的XML文档并说出您期望的结果。更多帮助:http://stackoverflow.com/help/mcve和http://stackoverflow.com/help/how-to-ask。 –

回答