mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 13:14:30 +03:00
correct complex data xml parsing
This commit is contained in:
parent
6b3792aef2
commit
2966c34352
|
@ -187,12 +187,11 @@ class XMLParser(BaseParser):
|
||||||
`data` will simply be a string representing the body of the request.
|
`data` will simply be a string representing the body of the request.
|
||||||
`files` will always be `None`.
|
`files` will always be `None`.
|
||||||
"""
|
"""
|
||||||
data = {}
|
|
||||||
tree = ET.parse(stream)
|
tree = ET.parse(stream)
|
||||||
data = self._xml_convert(tree.getroot())
|
data = self._xml_convert(tree.getroot())
|
||||||
|
|
||||||
return (data, None)
|
return (data, None)
|
||||||
|
|
||||||
def _xml_convert(self, element):
|
def _xml_convert(self, element):
|
||||||
"""
|
"""
|
||||||
convert the xml `element` into the corresponding python object
|
convert the xml `element` into the corresponding python object
|
||||||
|
@ -203,19 +202,15 @@ class XMLParser(BaseParser):
|
||||||
if len(children) == 0:
|
if len(children) == 0:
|
||||||
return self._type_convert(element.text)
|
return self._type_convert(element.text)
|
||||||
else:
|
else:
|
||||||
if element.tag == "resource":
|
# if the fist child tag is list-item means all children are list-item
|
||||||
|
if children[0].tag == "list-item":
|
||||||
data = []
|
data = []
|
||||||
for child in children:
|
for child in children:
|
||||||
data.append(self._xml_convert(child))
|
data.append(self._xml_convert(child))
|
||||||
else:
|
else:
|
||||||
if children[0].tag == "resource":
|
data = {}
|
||||||
data = []
|
for child in children:
|
||||||
for child in children:
|
data[child.tag] = self._xml_convert(child)
|
||||||
data.append(self._xml_convert(child))
|
|
||||||
else:
|
|
||||||
data = {}
|
|
||||||
for child in children:
|
|
||||||
data[child.tag] = self._xml_convert(child)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user