Revision 138
Added by Aaron Marcuse-Kubitza about 13 years ago
scripts/lib/xml_func.py | ||
---|---|---|
45 | 45 |
return ' '.join(parts) |
46 | 46 |
|
47 | 47 |
# Function names must start with _ to avoid collisions with real tags |
48 |
# Function names must be lowercase because name_of() returns name lowercased |
|
49 | 48 |
# Functions take arguments (doc, node) |
50 | 49 |
funcs = {'_alt': alt, '_range': range_, '_avg': avg, '_date': date, |
51 |
'_name': name, '_namepart': namePart}
|
|
50 |
'_name': name, '_namePart': namePart}
|
|
52 | 51 |
|
53 | 52 |
def process(doc, node=None): |
54 | 53 |
if node == None: node = doc.documentElement |
scripts/lib/xml_dom.py | ||
---|---|---|
13 | 13 |
|
14 | 14 |
def unescape(str_): return HTMLParser().unescape(str_) |
15 | 15 |
|
16 |
def name_of(node): return node.tagName.lower()
|
|
16 |
def name_of(node): return node.tagName |
|
17 | 17 |
|
18 | 18 |
def get_id(node): return node.getAttribute('id') |
19 | 19 |
|
scripts/lib/db_xml.py | ||
---|---|---|
12 | 12 |
|
13 | 13 |
ptr_suffix = '_id' |
14 | 14 |
|
15 |
def is_ptr(node_name): return node_name.endswith(ptr_suffix) |
|
15 |
def is_ptr(node_name): return node_name.lower().endswith(ptr_suffix)
|
|
16 | 16 |
|
17 | 17 |
def ptr_type(node_name): |
18 | 18 |
assert is_ptr(node_name) |
... | ... | |
54 | 54 |
return sql.select(db, table, fields, conds) |
55 | 55 |
|
56 | 56 |
def put(db, node, store_ids=False, row_ct_ref=None, pkeys=None, parent_id=None): |
57 |
# store_ids enables searching the tree for missing fields
|
|
57 |
'''store_ids enables searching the tree for missing fields'''
|
|
58 | 58 |
if pkeys == None: pkeys = {} |
59 | 59 |
def pkey(table): return sql.pkey(db, pkeys, table) |
60 | 60 |
|
... | ... | |
88 | 88 |
break |
89 | 89 |
except sql.NullValueException, ex: |
90 | 90 |
if try_num > 0: raise # exception still raised after retry |
91 |
if is_ptr(ex.col): |
|
91 |
if store_ids and is_ptr(ex.col):
|
|
92 | 92 |
# Search for required column in ancestors and their children |
93 | 93 |
target = find_by_name(node, ptr_type(ex.col)) |
94 | 94 |
if target == None: raise |
... | ... | |
103 | 103 |
def xml2db(db, node, row_ct_ref=None): |
104 | 104 |
iter_ = xml_dom.NodeElemIter(node) |
105 | 105 |
util.skip(iter_, xml_dom.is_text) # skip metadata |
106 |
for child in iter_: put(db, child, True, row_ct_ref) |
|
106 |
for child in iter_: put(db, child, False, row_ct_ref) |
Also available in: Unified diff
Made XML node names case-sensitive