2012-04-25 45 views
0

我有這個問題。我有一個包含此代碼的XML文件:XML DOMDocument php - 查詢

<Products> 
<Product> 
    <ID_Product>1</ID_Product> 
    <ID_ProductKind>green</ID_ProductKind> 
    <ID_ProductStatus>apple</ID_ProductStatus> 
    </Product> 
    <Product> 
    <ID_Product>2</ID_Product> 
    <ID_ProductKind>yellow</ID_ProductKind> 
    <ID_ProductStatus>banana</ID_ProductStatus> 
    </Product> 
</Products> 

現在我想選擇ID_ProductKind和ID_ProductStatus其中ID_Product等於一(1)。反正我查詢的結果應該是:

青蘋果

它是在MySQL中那麼簡單。我怎樣才能做到這一點在DOMDocument?

問候, 大衛

回答

0

我假設你正在尋找一個基本的XPath表達式。

這不是特別優雅,但你可以嘗試這樣的: 「// ID_ProductKind [之前的兄弟姐妹:: ID_Product ='1'] /文本()」。

您可以對ID_ProductStatus使用類似的東西。

我不太確定連接值 - 也許你可以在你的php代碼中處理這個。我發現XPath的更高版本中有一個字符串連接函數。