Revision 141
Added by Aaron Marcuse-Kubitza about 13 years ago
map | ||
---|---|---|
79 | 79 |
if in_is_xml: doc0 = xml.dom.minidom.parse(sys.stdin) |
80 | 80 |
if map_path != None: |
81 | 81 |
doc1 = xml_dom.create_doc(dest) |
82 |
root = doc1.documentElement |
|
82 | 83 |
if in_is_db: |
83 | 84 |
assert in_is_xpaths |
84 | 85 |
|
... | ... | |
97 | 98 |
row_id = str(row_id) |
98 | 99 |
|
99 | 100 |
def put_col(path, value): |
100 |
xpath.put_obj(doc1, path, row_id, has_types, value)
|
|
101 |
xpath.put_obj(root, path, row_id, has_types, value)
|
|
101 | 102 |
for value, out in metadata: put_col(out, value) |
102 | 103 |
for in_, out in mappings: |
103 |
root = xpath.get(in_.ownerDocument, src_root) |
|
104 |
xml_dom.replace(root, root.cloneNode(False)) |
|
105 |
xml_dom.set_id(root, row_id) |
|
106 |
|
|
104 |
in_ = in_.cloneNode(True) # don't modify orig value! |
|
105 |
xml_dom.set_id(xpath.get(in_, src_root), row_id) |
|
107 | 106 |
value = sql.value_or_none(db_xml.get(in_db, in_, in_pkeys)) |
108 | 107 |
if value != None: put_col(out, str(value)) |
109 | 108 |
in_db.close() |
... | ... | |
117 | 116 |
row_id = str(row_idx) |
118 | 117 |
|
119 | 118 |
def put_col(path, value): |
120 |
xpath.put_obj(doc1, path, row_id, has_types, value)
|
|
119 |
xpath.put_obj(root, path, row_id, has_types, value)
|
|
121 | 120 |
for value, out in metadata: put_col(out, value) |
122 | 121 |
for i, col in enumerate(cols): |
123 | 122 |
if row[i] != '' and col in map_: put_col(map_[col], row[i]) |
Also available in: Unified diff
xpath.py: Refactored to avoid needing a doc parameter for the XML document