Skip to content

XMLParser() item list #11

Open
Open
@av603

Description

@av603

As described in:
http://stackoverflow.com/questions/35631886/django-rest-xmlparser-cannot-parse-item-list

It appears XMLParser() does not support item lists. When parsing an XML list, the parser returns the last list item only (as a dict()). This behaviour is unexpected, and from what i can tell, not documented.

Example code follows: 
XML = """<?xml version="1.0" encoding="UTF-8"?>
                <root>
                <item>
                    <ID>item_1</ID>
                    <Description>first item</Description>
                </item>
                <item>
                    <ID>item_2</ID>
                    <Description>second item</Description>
                </item>
                </root>
            """
from django.conf import settings    
settings.configure()
from django.utils.six import BytesIO
from rest_framework_xml.parsers import XMLParser

data_stream = BytesIO(XML)
parsed_data = XMLParser().parse(data_stream)

print parsed_data

Which returns:

{'item': {'ID': 'item_2', 'Description': 'second item'}}

Given XML lists are common, and the code does not throw a warning/error; I would consider this a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions