Brand new to XML parsing. What would be the best way in python to parse something like:
<Item name="item1">
<data>item1data</data>
<subItems>
<Item name="item2">
<data>item2data</data>
<subItems>
<Item name="item3">
. . .
</Item>
</subItems>
</Item>
<Item name="item4">
. . .
</Item>
<subItems>
</Item>
I was looking at xml.sax parsing, but couldn’t figure out how to enable it to do multiple levels of parsing down the subItems trees. Could someone give me a recommendation of a parser/method to parse this? Thank you!
I will be creating lists of ‘Item’ objects with this, expected results would loopks something like this:
[Item(item1, item1data,
[Item(item2, item2data,
[Item(item3 ... ]) Item(item4 ... )])]`
One of the best ways in python to parse xml is to use the lxml package that can be located at:
http://lxml.de/
It includes backwards compatibility with the python built-in module ElementTree and provides xPath support.
Here’s a tutorial to get you started:
http://lxml.de/tutorial.html