[Tutor] Python XML for newbie
Sean Carolan
scarolan at gmail.com
Sun Jul 1 22:49:20 CEST 2012
I'm trying to parse some XML data (Book titles, ISBN numbers and
descriptions) with Python. Is there a *simple* way to import an XML
file into a dictionary, list, or other usable data structure? I've
poked around with minidom, elementtree, and "untangle" but am not
really understanding how they are supposed to work.
Here's some sample data:
<xml>
<fields>
<field>
<name>Title</name>
<id>2</id>
<count>1</count>
<type>11</type>
<search>true</search>
<hasnumber>false</hasnumber>
</field>
...several more fields, then there are the items...
</fields>
<items>
<item>
<id>108</id>
<data>
<datum>
<index>1</index>
<field>2</field>
<value>Essential System Administration</value>
</datum>
For starters, I'd like to be able to just print out the list of titles
in the XML file, using the correct XML parser. I don't mind doing
some research or reading on my own, but the official documentation
seems terribly confusing to me.
http://docs.python.org/library/xml.dom.minidom.html
Any pointers?
More information about the Tutor
mailing list