When using expat xml parser in python, how can I get it store the parsed the xml data in a string or in a file or in any data structure. Please show me a way to accomplish how to parse and use the nodes of the xml data.
Asked
Active
Viewed 2,331 times
0
-
Have you read http://docs.python.org/release/2.5.2/lib/expat-example.html ? – May 26 '11 at 09:44
-
Yeah! I'm using it but how do u store the input in some format? Don't try on flaunting your googling skills. Read my question properly!! – Mojo_Jojo May 26 '11 at 09:45
-
@Sentinel: Why should he read old stuff like the 2.5 docs? BTW, the last non-security release was 2.5.4 – John Machin May 26 '11 at 11:52
1 Answers
7
Why are you using a low-level interface like the expat parser when you can use xml.etree.[c]ElementTree? It creates a tree of elements (nodes) for you. Elements have tag, text, and tail attributes and contain a dict that maps attribute names to values, and a list of child elements.
Have a look at the Python documentation for xml.etree.ElementTree, and this additional information.

John Machin
- 81,303
- 11
- 141
- 189