Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-fold style list #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

jeffkit
Copy link

@jeffkit jeffkit commented Jul 29, 2015

By default, a list element was convert to a set of tag wrap in the name tag(parent tag).

>>> data = {'mylist': ['hello', 'world']}
>>> dicttoxml.dicttoxml(data, attr_type=False)
'<?xml version="1.0" encoding="UTF-8" ?><root><mylist><item>hello</item><item>world</item></mylist></root>'

Some times, we need other style of list:

'<?xml version="1.0" encoding="UTF-8" ?><root><mylist>hello</mylist><mylist>world</mylist></root>'

so, I add a optional argument to the dicttoxml method: fold_list, default value is True, act as usual, when set to False, the list style will change to non-fold style.

BTW: I made the code style PEP8 compatible.

@jeffkit jeffkit closed this Jul 29, 2015
@jeffkit jeffkit reopened this Jul 29, 2015
@quandyfactory
Copy link
Owner

The latest version includes the ability to customize the name of the item elements. Does this change meet your requirements?

@wisotzky
Copy link

I think the use-case is valid. Assuming the following instance of data should be translated to XML:

{
            "book": [
                {
                    "license": "GPL", 
                    "title": "Python Programming"
                }, 
                {
                    "license": "Apache 2.0", 
                    "title": "Business Modelling"
                }
            ]
}

Using dicttoxml typically the output would look like this:

<library>
  <book>
    <item>
      <license>GPL</license>
      <title>Python Programming</title>
    </item>
    <item>
      <license>Apache 2.0</license>
      <title>Business Modelling</title>
    </item>
  </book>
</library >

But what you want is to avoid additional folding:

<library>
  <book>
    <license>GPL</license>
    <title>Python Programming</title>
  </book>
  <book>
    <license>Apache 2.0</license>
    <title>Business Modelling</title>
  </book>
</library >

Such flat list rendering is currently not supported. And even having the possibility to change the customize the item element naming does not really help, as we cannot suppress the creation of the list-level element.

I've play around quite a bit with various input structures, but without any helpful format. Such as

[{'book': {'license': 'GPL', 'title': 'Python Programming'}}, {'book': {'license': 'Apache 2.0', 'title': 'Business Modelling'}}]

@wisotzky
Copy link

This PR is now obsoleted by PR #64, merging the code proposal with the latest release of dicttoxml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants