I'm making a call to an API endpoint, and the data is returned in xml format. I'm using 'xml2js' to convert it to json format, but there is a huge amount of data being converted, and it's crashing quite a lot.
The thing is, I only need a small amount of the xml data that is returned. The xml data that is returned looks something like this...
<odds>
<event>
<market id="16336888" state="open" slug="winner" winners="1" traded_volume="0">
<contract id="54475601" name="Raya2" slug="home" state_or_outcome="open" volume="0.0">
<bids/>
<offers/>
</contract>
<contract id="54475603" name="Draw" slug="draw" state_or_outcome="open" volume="0.0">
<bids/>
<offers/>
</contract>
<contract id="54475602" name="Club Celaya" slug="away" state_or_outcome="open" volume="0.0">
<bids/>
<offers/>
</contract>
</market>
</market></market>
<market>...</market>
<market>...</market>
<market>...</market>
... // more markets
</event>
<event>...</event>
<event>...</event>
<event>...</event>
.. // more events
</odds>
From this xml, I need every event, but I only need the first market in each event (market with 'slug' = 'winner'). Is there a way I can cut all the 'markets' I don't need from each 'event' tag, so less xml has to be converted to json?