0

これがXML構造です

<Row type='apple' price='1' quantity='6' date='2013-06-08' transactiontype='sell'/>
<Row type='apple' price='1.5' quantity='3' date='2013-06-07' transactiontype='buy'/>
<Row type='apple' price='1.4' quantity='2' date='2013-06-05' transactiontype='buy'/>
<Row type='orange' price='4' quantity='5' date='2013-06-05' transactiontype='sell'/>

私の現在のクエリは

//row[@type='apple' and @transactiontype='buy']/attribute::price

しかし、このクエリでは日付範囲を選択できません。2013 年 6 月 6 日から 2013 年 6 月 8 日までのすべての取引日を許可したい場合、クエリをどのように編集すればよいですか?

4

1 に答える 1

2

XPath 1.0 には日付型の概念がないため (使用していると思われます)、日付文字列を数値に変換する必要があります (文字列は <、<=、>、または => と比較できません)。日付値を20130608XML に直接書き込むか、translate関数を使用して比較のダッシュを削除することができます。

2 番目のオプションの有効な XPath 式は次のようになります。

//Row[@type='apple' and @transactiontype='buy' and 
  (translate(@date, '-', '') >= 20130606 and 
   translate(@date, '-', '') <= 20130608)]/attribute::price
于 2013-06-09T10:07:01.090 に答える