0

I have a rails service reading an XML from a SOAP endpoint. The simplified structure is like:

<resource id="1287085300000102889" ...>
  <prices>
   <price datefrom="2018-05-25" dateto="2018-05-26" price="0.0" currency="EUR"/>
   <price datefrom="2019-07-12" dateto="2019-07-13" price="1000.0" currency="EUR"/>

   <price datefrom="2020-05-23" dateto="2020-05-24" price="1540.0" currency="EUR"/>
   ...
  </prices>
</resource>

I´m parsing the information using Nokogiri gem that I think uses xpath. I would like to filter out all the prices of last year. I´m trying to do

prices = resource.xpath(".//prices/price[@dateto > '2019-01-01']")

but it´s not working.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Rober
  • 5,868
  • 17
  • 58
  • 110

1 Answers1

0

You can convert date string to number like this and then compare:

prices = resource.xpath(".//prices/price[translate(@dateto, '-', '') > 20190101]")
Kamal
  • 2,384
  • 1
  • 13
  • 25
  • Well according to the link in the comment from @har07 It´s working by adding the function number before, like resource.xpath(".//prices/price[number(translate(@dateto, '-', '')) > 20190101] . I haven´t tried without it, but hope it works too. – Rober Feb 20 '19 at 08:36