Project

General

Profile

« Previous | Next » 

Revision 963

xml_dom.py: replace(): Added support for new node that's None (deletes existing node)

View differences:

lib/xml_dom.py
165 165

  
166 166
def remove(node): node.parentNode.removeChild(node)
167 167

  
168
def replace(old_node, new_node):
169
    old_node.parentNode.replaceChild(new_node, old_node) # note order reversed
168
def replace(old, new):
169
    '''@param new Node|None'''
170
    if new == None: old.parentNode.removeChild(old)
171
    else: old.parentNode.replaceChild(new, old) # note order reversed
170 172

  
171 173
def replace_with_text(node, new):
172 174
    if util.is_str(new): new = node.ownerDocument.createTextNode(new)

Also available in: Unified diff