XML to dictionary?

johnjensen at my-deja.com johnjensen at my-deja.com
Thu Jan 6 00:19:32 EST 2000


I have a relatively simple XML question, but I can't seem to figure out
how to do it simply and easily with the xmllib module.

Assume I have some XML (stylized below):

<Newsgroup>
  <comp.lang.python>
    <Message1>
      <Subject>Hi there</Subject>
      <Body>This is a test</Body>
    </Message1>
  </comp.lang.python>
</Newsgroup>

How can I quickly and easily stuff this into a nested dictionary, so
that:

print dict['Newsgroup']['comp.lang.python']['Message1']['Subject']
spits out 'Hi there'

The XML I am working with is perfect for this type of solution.

Any help would be appreciated!

John


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list