2016-10-07 63 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。 –

回答