Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Add xmltodict to xml scenario. #311

merged 1 commit into from

2 participants


No description provided.


@kennethreitz Would you consider adding xmltodict to the xml section of your python guide? Thanks!


@martinblech absolutely :)

@kennethreitz kennethreitz merged commit 6b53b2f into from

@kennethreitz cool, thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 29, 2013
  1. @martinblech

    Add xmltodict

    martinblech authored
This page is out of date. Refresh to see the latest.
Showing with 39 additions and 0 deletions.
  1. +39 −0 docs/scenarios/xml.rst
39 docs/scenarios/xml.rst
@@ -32,3 +32,42 @@ and then you can get the child elements name like this:
untangle also supports loading XML from a string or an URL.
+`xmltodict <>`_ is another simple
+library that aims at making xml feel like working with json.
+An xml file like this:
+.. code-block:: xml
+ <mydocument has="an attribute">
+ <and>
+ <many>elements</many>
+ <many>more elements</many>
+ </and>
+ <plus a="complex">
+ element as well
+ </plus>
+ </mydocument>
+can be loaded into a python dict like this:
+.. code-block:: python
+ import xmltodict
+ obj = xmltodict.parse('path/to/file.xml')
+and then you can access elements, attributes and values like this:
+.. code-block:: python
+ doc['mydocument']['@has'] # == u'an attribute'
+ doc['mydocument']['and']['many'] # == [u'elements', u'more elements']
+ doc['mydocument']['plus']['@a'] # == u'complex'
+ doc['mydocument']['plus']['#text'] # == u'element as well'
+xmltodict also lets you roundtrip back to xml with the unparse function,
+has a streaming mode suitable for handling files that don't fit in memory
+and supports namespaces.
Something went wrong with that request. Please try again.