2013-02-25 87 views
1

我正在使用Kettle和「從XML獲取數據」轉換從XML文件中提取某些信息。我將Loop Xpath設置爲/*[name()='feed']/*[name()='entry'],它引入了所有相關的字段。如何從循環節點中提取XML節點值和屬性

我想從region節點中提取每個<region>節點作爲其自己的字段,以便稍後可以使用「/」分隔符連接它們。

接下來,我需要爲每個<rate>節點創建類似weekly_rate_fromweekly_rate_to的字段。我不能完全弄清楚Xpath來區分諸如periodType之類的屬性,然後也從中提取信息。換句話說,我只需要提取「到」和「從」速度屬性時periodType =每週

但願這不是太混亂,我可能沒有解釋好

<feed> 
<entry> 
    <content> 
    <listing>  
     <regions> 
     <region>World</region> 
     <region>USA</region> 
     <region>California</region> 
     <region>Inland Empire California</region> 
     <region>Temecula Valley</region> 
     <region>Temecula</region> 
     </regions> 
     <rates rentalBasis="property"> 
     <rate from="3395" to="4175" currencyUnit="USD" periodType="weekly"/> 
     <rate from="599" to="749" currencyUnit="USD" periodType="nightly-weekday"/> 
     <rate from="799" to="1019" currencyUnit="USD" periodType="nightly-weekend"/> 
     </rates> 
    </listing> 
    </content> 
</entry> 
<entry> 
... 
</entry> 
... for a total of 20 "entry" nodes 
</feed> 

回答

2

計數所有區域元素:

count(/feed/entry/content/listing/regions/region) 

僅檢索periodType每週fromto

/feed/entry/content/listing/rates/rate[@periodType = 'weekly']/@from 
/feed/entry/content/listing/rates/rate[@periodType = 'weekly']/@to 
+0

謝謝!我在Xpath上並不是很清楚,所以我不知道如何獲得「每週」屬性。 – 2013-02-26 18:06:19