Guest User

xmltodict ElasticSearch

a guest
Nov 27th, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. >>> import xmltodict
  2. >>>
  3. >>> x = """
  4. ... <xml>
  5. ...  <group title="persons">
  6. ...  <person>John</person>
  7. ...  </group>
  8. ... </xml>
  9. ... """
  10. >>>
  11. >>> j1 = xmltodict.parse(x)
  12. >>> j1
  13. OrderedDict([(u'xml', OrderedDict([(u'group', OrderedDict([(u'@title', u'persons'), (u'person', u'John')]))]))])
  14. >>>
  15. >>> x = """
  16. ... <xml>
  17. ...  <group title="persons">
  18. ...   <person>John</person>
  19. ...   <person>John</person>
  20. ...  </group>
  21. ... </xml>
  22. ... """
  23. >>>
  24. >>> j2 = xmltodict.parse(x)
  25. >>> j2
  26. OrderedDict([(u'xml', OrderedDict([(u'group', OrderedDict([(u'@title', u'persons'), (u'person', [u'John', u'John'])]))]))])
  27. >>>
  28. >>> j1['xml']['group']['person']
  29. u'John'
  30. >>> j2['xml']['group']['person']
  31. [u'John', u'John']
  32. >>> type(j1['xml']['group']['person'])
  33. <type 'unicode'>
  34. >>> type(j2['xml']['group']['person'])
  35. <type 'list'>
  36. >>>
Advertisement
Add Comment
Please, Sign In to add comment