Project

General

Profile

« Previous | Next » 

Revision 143

Refactored xml_dom.set_value() to avoid needing a doc parameter for the XML document

View differences:

scripts/lib/xml_dom.py
78 78
    if node.firstChild != None: return node.firstChild.nodeValue
79 79
    else: return node.nodeValue
80 80

  
81
def set_value(doc, node, value):
81
def set_value(node, value):
82 82
    if node.nodeType == Node.ELEMENT_NODE:
83
        node.appendChild(doc.createTextNode(value))
83
        node.appendChild(node.ownerDocument.createTextNode(value))
84 84
    else: node.nodeValue = value
85 85

  
86 86
class NodeTextEntryIter:
......
102 102
def set_child(node, name, value):
103 103
    '''Note: does not remove any existing child of the same name'''
104 104
    child = node.ownerDocument.createElement(name)
105
    set_value(node.ownerDocument, child, value)
105
    set_value(child, value)
106 106
    node.appendChild(child)
107 107

  
108 108
def replace(old_node, new_node):
scripts/lib/xpath.py
171 171
                parent.setAttribute(elem.name, '')
172 172
                node = parent.getAttributeNode(elem.name)
173 173
            else: node = parent.appendChild(doc.createElement(elem.name))
174
            if elem.value != None: xml_dom.set_value(doc, node, elem.value)
174
            if elem.value != None: xml_dom.set_value(node, elem.value)
175 175
        if create:
176 176
            for attr in elem.keys + elem.attrs:
177 177
                get(node, attr, create, last_only)
......
203 203
                    
204 204
                    # Will append if target keys didn't match. Place ! in XPath
205 205
                    # after element to fork at to avoid this.
206
                    xml_dom.set_value(doc, node, id_)
206
                    xml_dom.set_value(node, id_)
207 207
                else: last_only = False
208 208
                set_id(xpath, id_)
209 209
            return get(root, xpath, create, last_only)

Also available in: Unified diff