Revision 116
Added by Aaron Marcuse-Kubitza about 13 years ago
map | ||
---|---|---|
65 | 65 |
stream.close() |
66 | 66 |
|
67 | 67 |
# Input datasource to XML tree, mapping if needed |
68 |
if in_is_xml: doc = xml.dom.minidom.parse(sys.stdin) |
|
68 |
if in_is_xml: doc0 = xml.dom.minidom.parse(sys.stdin)
|
|
69 | 69 |
if map_path != None: |
70 |
out_doc = xml.dom.minidom.getDOMImplementation().createDocument(None,
|
|
70 |
doc1 = xml.dom.minidom.getDOMImplementation().createDocument(None,
|
|
71 | 71 |
dest, None) |
72 | 72 |
if in_is_xml: raise Exception('XML-XML mapping not supported yet') |
73 | 73 |
elif in_is_db: raise Exception('DB-XML mapping not supported yet') |
... | ... | |
84 | 84 |
for row_idx, row in enumerate(reader): |
85 | 85 |
row_id = str(row_idx) |
86 | 86 |
def put_col(path, value): |
87 |
xpath.put_obj(out_doc, path, row_id, has_types, value)
|
|
87 |
xpath.put_obj(doc1, path, row_id, has_types, value)
|
|
88 | 88 |
for value, out in metadata: put_col(out, value) |
89 | 89 |
for i, col in enumerate(cols): |
90 | 90 |
if row[i] != '' and col in map_: put_col(map_[col], row[i]) |
91 |
xml_func.process(out_doc)
|
|
92 |
doc = out_doc
|
|
91 |
xml_func.process(doc1)
|
|
92 |
else: doc1 = doc0
|
|
93 | 93 |
|
94 | 94 |
# Output XML tree |
95 | 95 |
if out_db_config != None: # output is database |
... | ... | |
102 | 102 |
db.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) |
103 | 103 |
try: |
104 | 104 |
row_ct_ref = [0] |
105 |
db_xml.xml2db(db, doc.documentElement, row_ct_ref) |
|
105 |
db_xml.xml2db(db, doc1.documentElement, row_ct_ref)
|
|
106 | 106 |
print 'Inserted '+str(row_ct_ref[0])+' rows' |
107 | 107 |
if commit: db.commit() |
108 | 108 |
finally: |
109 | 109 |
db.rollback() |
110 | 110 |
db.close() |
111 |
else: doc.writexml(sys.stdout, addindent=' ', newl='\n') # output is XML |
|
111 |
else: doc1.writexml(sys.stdout, addindent=' ', newl='\n') # output is XML
|
|
112 | 112 |
|
113 | 113 |
main() |
Also available in: Unified diff
Started preparing map to input from DB