Project

General

Profile

« Previous | Next » 

Revision 1836

xml_dom.py: get_id(): If the node doesn't have an ID, assumes the node itself is the ID. This enables backward (child-to-parent) pointers whose target is a text element containing an ID, rather than a regular element with an ID attribute.

View differences:

lib/xml_dom.py
24 24
    if sep != '': return base
25 25
    else: return name
26 26

  
27
##### IDs
28

  
29
def get_id(node): return node.getAttribute('id')
30

  
31
def set_id(node, id_): node.setAttribute('id', id_)
32

  
33 27
##### Element node contents
34 28

  
35 29
def is_elem(node): return node.nodeType == Node.ELEMENT_NODE
......
180 174
    def __init__(self, iterable):
181 175
        util.CheckedIter.__init__(self, is_text_node_entry, iterable)
182 176

  
177
##### IDs
178

  
179
def get_id(node):
180
    '''If the node doesn't have an ID, assumes the node itself is the ID.
181
    @return None if the node doesn't have an ID or a value
182
    '''
183
    id_ = node.getAttribute('id')
184
    if id_ != '': return id_
185
    else: return value(node) # assume the node itself is the ID
186

  
187
def set_id(node, id_): node.setAttribute('id', id_)
188

  
183 189
##### Modifying/replacing a node
184 190

  
185 191
def set_child(node, name, value):
lib/db_xml.py
52 52
        elif xml_dom.is_text(child): conds[child_name] = xml_dom.value(child)
53 53
        else: raise Exception('Joins not supported yet')
54 54
    id_ = xml_dom.get_id(node)
55
    if id_ != '': conds[pkey(table)] = id_ # replace any existing pkey value
55
    if id_ != None: conds[pkey(table)] = id_ # replace any existing pkey value
56 56
    if fields == []: fields.append(pkey_)
57 57
    
58 58
    return sql.select(db, table, fields, conds, limit, start)

Also available in: Unified diff