Skip to content

Multiple elements of the same name? #59

Description

@BobStein

I need to generate some XML from a Python dictionary that has multiple elements of the same name.

<country>
    <city>Chicago</city>
    <city>Boston</city>
</country>

Obviously the following won't work. I assumed it would produce a syntax error, but it simply hides one of the keys:

>>> from dicttoxml import dicttoxml
>>> dicttoxml({'country':{'city':'Chicago', 'city': 'Boston'}}, attr_type=False, root=False)
'<country><city>Boston</city></country>'

I tried a list, but that wraps each list element in an item element:

>>> dicttoxml({ 'country': [ {'city': 'Chicago'}, {'city': 'Boston'} ] }, attr_type=False, root=False)
'<country><item><city>Chicago</city></item><item><city>Boston</city></item></country>'

Here's what I want the output to be

'<country><city>Chicago</city><city>Boston</city></country>'

What dictionary and/or function call settings (e.g. item_func=None) would produce that?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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