Revision 2433
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/xml_func.py | ||
---|---|---|
87 | 87 |
|
88 | 88 |
on_error(e) |
89 | 89 |
|
90 |
def strip(node): |
|
90 |
def strip(node, preserve=set()):
|
|
91 | 91 |
'''Replaces every XML function with its last parameter (which is usually its |
92 |
value), except for _ignore, which is removed completely''' |
|
93 |
for child in xml_dom.NodeElemIter(node): strip(child) |
|
92 |
value), except for _ignore, which is removed completely |
|
93 |
@param preserve set(str...) XML functions not to remove. |
|
94 |
* container can be any iterable type |
|
95 |
''' |
|
96 |
preserve = set(preserve) |
|
97 |
|
|
98 |
for child in xml_dom.NodeElemIter(node): strip(child, preserve) |
|
94 | 99 |
name = node.tagName |
95 |
if is_xml_func_name(name): |
|
100 |
if is_xml_func_name(name) and name not in preserve:
|
|
96 | 101 |
if name == '_ignore': value = None |
97 | 102 |
else: value = pop_value(list(xml_dom.NodeTextEntryIter(node)), None) |
98 | 103 |
xml_dom.replace_with_text(node, value) |
Also available in: Unified diff
xml_func.py: strip(): Added preserve param for XML functions not to remove