Revision 661
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/xml_dom.py | ||
---|---|---|
108 | 108 |
self.node = self.node.parentNode |
109 | 109 |
return node |
110 | 110 |
|
111 |
def is_simple(node): |
|
112 |
'''Whether every child recursively has no more than one child''' |
|
113 |
return (not is_elem(node) or is_completely_empty(node) |
|
114 |
or (has_one_child(node) and is_simple(node.firstChild))) |
|
115 |
|
|
111 | 116 |
##### |
112 | 117 |
|
113 | 118 |
def is_text_node(node): return node.nodeType == Node.TEXT_NODE |
... | ... | |
184 | 189 |
|
185 | 190 |
minidom.Node.__iter__ = lambda self: NodeIter(self) |
186 | 191 |
|
187 |
minidom.Node.__str__ = lambda self: self.toprettyxml(**toprettyxml_config) |
|
192 |
def __Node_str(self): |
|
193 |
if is_simple(self): return self.toxml() |
|
194 |
else: return self.toprettyxml(**toprettyxml_config) |
|
195 |
minidom.Node.__str__ = __Node_str |
|
188 | 196 |
|
189 | 197 |
minidom.Node.pop = lambda self: self.removeChild(self.lastChild) |
190 | 198 |
|
Also available in: Unified diff
xml_dom.py: Added is_simple() to determine whether every child recursively has no more than one child. Used is_simple() to print condensed XML when simple nodes are converted to a string.