def _build_xml(self, tag, val=None, children=Void()):
"""Construct an xml element with a given tag, value, and children."""
attribs = {'val': val} if val is not None else {}
# If children is a list then convert each element separately, if it is
# a tuple, treat it as a single element
if isinstance(children, self.Void):
children = ()
elif isinstance(children, list):
children = [self._from_value(child) for child in children]
else:
children = (self._from_value(children),)
xml = ET.Element(tag, attribs)
xml.extend(children)
return xml
评论列表
文章目录