aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/parsers.py
diff options
context:
space:
mode:
authorMarko Tibold2012-01-13 12:36:02 -0800
committerMarko Tibold2012-01-13 12:36:02 -0800
commitc204101563bce0997e46ad5381d6d410f570b233 (patch)
tree99e3ef2b2bd00ac6b5fbf0579f2989f868cdc6cf /djangorestframework/parsers.py
parentc71b6fb090b7a225869526b1d75d7e850e85c282 (diff)
parent21776c0de2eca3d66534817b3f5a258a6fc1fc2f (diff)
downloaddjango-rest-framework-c204101563bce0997e46ad5381d6d410f570b233.tar.bz2
Merge pull request #125 from michelelazzeri-nextage/master
application/xml parser fully compatible with application/xml render
Diffstat (limited to 'djangorestframework/parsers.py')
-rw-r--r--djangorestframework/parsers.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py
index c218e5ee..b99423a0 100644
--- a/djangorestframework/parsers.py
+++ b/djangorestframework/parsers.py
@@ -187,13 +187,33 @@ class XMLParser(BaseParser):
`data` will simply be a string representing the body of the request.
`files` will always be `None`.
"""
- data = {}
tree = ET.parse(stream)
- for child in tree.getroot().getchildren():
- data[child.tag] = self._type_convert(child.text)
-
+ data = self._xml_convert(tree.getroot())
+
return (data, None)
-
+
+ def _xml_convert(self, element):
+ """
+ convert the xml `element` into the corresponding python object
+ """
+
+ children = element.getchildren()
+
+ if len(children) == 0:
+ return self._type_convert(element.text)
+ else:
+ # if the fist child tag is list-item means all children are list-item
+ if children[0].tag == "list-item":
+ data = []
+ for child in children:
+ data.append(self._xml_convert(child))
+ else:
+ data = {}
+ for child in children:
+ data[child.tag] = self._xml_convert(child)
+
+ return data
+
def _type_convert(self, value):
"""
Converts the value returned by the XMl parse into the equivalent