Revision 2597
Added by Aaron Marcuse-Kubitza over 12 years ago
xml_func.py | ||
---|---|---|
65 | 65 |
|
66 | 66 |
def is_xml_func(node): return is_xml_func_name(node.tagName) |
67 | 67 |
|
68 |
def process(node, on_error=exc.raise_, db=None): |
|
69 |
for child in xml_dom.NodeElemIter(node): process(child, on_error) |
|
68 |
def process(node, on_error=exc.raise_, db=None, preserve=set(), strip=False): |
|
69 |
'''Evaluates the XML functions in an XML tree. |
|
70 |
@param preserve set(str...) XML functions not to remove. |
|
71 |
* container can be any iterable type |
|
72 |
@param strip Whether to instead replace most XML functions with their last |
|
73 |
parameter (usually the value) and evaluate only structural functions |
|
74 |
''' |
|
75 |
preserve = set(preserve) |
|
76 |
|
|
77 |
for child in xml_dom.NodeElemIter(node): |
|
78 |
process(child, on_error, db, preserve, strip) |
|
70 | 79 |
name = node.tagName |
71 |
if is_func_name(name): |
|
80 |
if not is_xml_func_name(name) or name in preserve: pass |
|
81 |
elif strip and name not in structural_funcs: # just replace with last param |
|
82 |
value = pop_value(list(xml_dom.NodeTextEntryIter(node)), None) |
|
83 |
xml_dom.replace_with_text(node, value) |
|
84 |
else: |
|
72 | 85 |
try: |
73 | 86 |
items = xml_dom.NodeTextEntryIter(node) |
74 | 87 |
try: func = funcs[name] |
Also available in: Unified diff
xml_func.py: process(): Added strip()'s functionality via strip option