Skip to content
This repository was archived by the owner on Jan 3, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions huTools/structured.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,14 @@ def dict2et(xmldict, roottag='data', listnames=None):
return root


def list2et(xmllist, root, elementname):
def list2et(xmllist, root, elementname, listnames={}):
"""Converts a list to an Elementtree.

See also dict2et()
"""

basexml = dict2et({root: xmllist}, 'xml', listnames={root: elementname})
listnames[root] = elementname
basexml = dict2et({root: xmllist}, 'xml', listnames)
return basexml.find(root)


Expand All @@ -311,12 +312,12 @@ def dict2xml(datadict, roottag='data', listnames=None, pretty=False):
return ET.tostring(tree, 'utf-8')


def list2xml(datalist, root, elementname, pretty=False):
def list2xml(datalist, root, elementname, listnames=None, pretty=False):
"""Converts a list to an UTF-8 encoded XML string.

See also dict2et()
"""
tree = list2et(datalist, root, elementname)
tree = list2et(datalist, root, elementname, listnames)
if pretty:
indent(tree)
return ET.tostring(tree, 'utf-8')
Expand Down