sax-machine
sax-machine copied to clipboard
Is it me or the selectors being buggy?
<vehicle lang="de-DE">
<mainData>
</mainData>
<options>
<option id="1">
<value>5</value>
<name>5 Türen</name>
<description>Türen</description>
</option>
<option id="2">
<value>5</value>
<name>5 Sitze</name>
<description>Sitze</description>
</option>
</options>
<equipment/>
<colors>
<bodyColors>
<bodyColor id="12">
<name>silber</name>
<description>Platin-Grau (D69)</description>
<paint id="2">metallic</paint>
</bodyColor>
</bodyColors>
</colors>
<dates>
<date id="2">2016-06-01</date>
<date id="3">2019-04-01</date>
</dates>
<reservations/>
<description>Dealer-of-the-Year-Sonderpreis</description>
<package/>
</vehicle>
class Vehicle
include SAXMachine
element "description", as: :main_description, within: '.'
element "description", as: :color, within: 'bodyColor'
end
class XmlParser
include SAXMachine
elements "vehicle", as: :vehicles, class: Vehicle
end
p = XmlParser.parse(xml)
p.vehicles.first
#=> #<Vehicle:0x007fc5213ec608 @main_description="Türen">
As you can see, neither the color
nor the main_description
is found correctly
Hmm I see now, that the within:
operator is not yet implemented. How would you go about solving this one then?