diff options
| author | Michele Lazzeri | 2012-01-11 18:58:43 +0100 |
|---|---|---|
| committer | Michele Lazzeri | 2012-01-11 18:58:43 +0100 |
| commit | f461acbaf28aa79d82cffaf65b886c3d884cc5f4 (patch) | |
| tree | c31543e208498bb75337b5cc33237bd09eb13b1b /djangorestframework/parsers.py | |
| parent | c71b6fb090b7a225869526b1d75d7e850e85c282 (diff) | |
| download | django-rest-framework-f461acbaf28aa79d82cffaf65b886c3d884cc5f4.tar.bz2 | |
update author
Diffstat (limited to 'djangorestframework/parsers.py')
| -rw-r--r-- | djangorestframework/parsers.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index c218e5ee..c5eefaec 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -189,11 +189,38 @@ class XMLParser(BaseParser): """ 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 + + `data` The python object representation of xml `element`. + """ + + children = element.getchildren() + + if len(children) == 0: + return self._type_convert(element.text) + else: + if element.tag == "resource": + data = [] + for child in children: + data.append(self._xml_convert(child)) + else: + if children[0].tag == "resource": + 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 |
