XML to dictionary?
Randall Hopper
aa8vb at yahoo.com
Fri Jan 7 09:28:32 EST 2000
Matt Gushee:
|from pyxie import File2PYX # PYX is the notation pyxie uses for
|import string # parsed XML
|
|f = File2PYX('hithere.xml')
|data = f.read()
|f.close()
|data = string.split(data)
|
|dict = {}
|for line in data:
| if line[0] = '(': # '(' at the beginning of the line in
| # PYX indicates an element
Pyxie is a good tool. But just to pick nits, using string.split isn't safe
with Pyxie output. :-)
Consider:
<?xml version = "1.0"?>
<Greeting>
Wishing You A Merry Christmas!
From all of us (here at the White House)
Author: --Unknown
</Greeting>
string.split gives you a new start tag, attribute, and text element you
didn't know you had ;-)
--
Randall Hopper
aa8vb at yahoo.com
More information about the Python-list
mailing list