Project

General

Profile

« Previous | Next » 

Revision 4029

xml_dom.py: set_value(): Don't set the value of a text node to None by removing it, because this prevents the node from being reused. Instead use a sentinel string value to denote None, and map to and from it.

View differences:

lib/xml_dom.py
173 173
    else: return node
174 174

  
175 175
def value(node):
176
    return util.do_ignore_none(lambda n: n.nodeValue, value_node(node))
176
    value_ = util.do_ignore_none(lambda n: n.nodeValue, value_node(node))
177
    if value_ is strings.none_str: value_ = None # text node's None
178
    return value_
177 179

  
178 180
def is_whitespace(node): return is_text_node(node) and value(node).isspace()
179 181

  
......
186 188
            assert is_elem(node)
187 189
            node.appendChild(node.ownerDocument.createTextNode(value))
188 190
    elif value_node_ != None:
189
        if is_elem(node) or is_text_node(node): remove(value_node_)
190
        else: node.nodeValue = value
191
        if is_elem(node): remove(value_node_)
192
        else:
193
            if is_text_node(node): value = strings.none_str # text node's None
194
            node.nodeValue = value
191 195

  
192 196
class NodeTextEntryIter:
193 197
    def __init__(self, node): self.iter_ = NodeElemIter(node)

Also available in: Unified diff