Project

General

Profile

« Previous | Next » 

Revision 142

xpath.py: Refactored xml_func.py to avoid needing a doc parameter for the XML document

View differences:

scripts/lib/xml_func.py
49 49
funcs = {'_alt': alt, '_range': range_, '_avg': avg, '_date': date,
50 50
    '_name': name, '_namePart': namePart}
51 51

  
52
def process(doc, node=None):
53
    if node == None: node = doc.documentElement
52
def process(node):
54 53
    name = node.tagName
55
    if name.startswith('_') and name in funcs: xml_dom.replace_with_text(doc,
56
        node, funcs[name](xml_dom.NodeTextEntryIter(node)))
54
    if name.startswith('_') and name in funcs: xml_dom.replace_with_text(node,
55
        funcs[name](xml_dom.NodeTextEntryIter(node)))
57 56
    else:
58
        for child in xml_dom.NodeElemIter(node): process(doc, child)
57
        for child in xml_dom.NodeElemIter(node): process(child)
scripts/lib/xml_dom.py
108 108
def replace(old_node, new_node):
109 109
    old_node.parentNode.replaceChild(new_node, old_node) # note order reversed
110 110

  
111
def replace_with_text(doc, node, str_): replace(node, doc.createTextNode(str_))
111
def replace_with_text(node, str_):
112
    replace(node, node.ownerDocument.createTextNode(str_))
112 113

  
113 114
def by_tag_name(node, name, last_only=False):
114 115
    '''last_only optimization returns last matching node'''
scripts/map
120 120
                for value, out in metadata: put_col(out, value)
121 121
                for i, col in enumerate(cols):
122 122
                    if row[i] != '' and col in map_: put_col(map_[col], row[i])
123
        xml_func.process(doc1)
123
        xml_func.process(root)
124 124
    else: doc1 = doc0
125 125
    
126 126
    # Output XML tree

Also available in: Unified diff