Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> import xmltodict
- >>>
- >>> x = """
- ... <xml>
- ... <group title="persons">
- ... <person>John</person>
- ... </group>
- ... </xml>
- ... """
- >>>
- >>> j1 = xmltodict.parse(x)
- >>> j1
- OrderedDict([(u'xml', OrderedDict([(u'group', OrderedDict([(u'@title', u'persons'), (u'person', u'John')]))]))])
- >>>
- >>> x = """
- ... <xml>
- ... <group title="persons">
- ... <person>John</person>
- ... <person>John</person>
- ... </group>
- ... </xml>
- ... """
- >>>
- >>> j2 = xmltodict.parse(x)
- >>> j2
- OrderedDict([(u'xml', OrderedDict([(u'group', OrderedDict([(u'@title', u'persons'), (u'person', [u'John', u'John'])]))]))])
- >>>
- >>> j1['xml']['group']['person']
- u'John'
- >>> j2['xml']['group']['person']
- [u'John', u'John']
- >>> type(j1['xml']['group']['person'])
- <type 'unicode'>
- >>> type(j2['xml']['group']['person'])
- <type 'list'>
- >>>
Advertisement
Add Comment
Please, Sign In to add comment