stchris / untangle

Converts XML to Python objects
MIT License
612 stars 83 forks source link

How to access sibling list members #54

Closed tmccoy00 closed 2 years ago

tmccoy00 commented 6 years ago

I have a weather forecast file and want to improve the reliability of some code that is a nested sibling in the area.forecast-period lists.

I want to get the Icon Code, Maximum and Minimum from each of the forecast period index 1, 2 and 3 which is the next 3 days weather forecast.

Right now my code is hardcoded such as area[2].forecast_period[1].element[0].cdata but there are variations in the ordering of the "elements" such as in forecast period index 3 where a rainfall forecast is in the element[1] position instead of the minimums in indexes 1 and 2 in this example below.

How can I avoid using static list position numbers and use the element type attribute text as the reference to access the cdata value? It would sort of look like:

icon_code = area[2].forecast_period[1].element[type="forecast_icon_code"].cdata

...but I can't seem to get this to work properly!

IDV10450.txt

stchris commented 2 years ago

Closing as out of scope for what untangle is supposed to do.