Revision 57
Added by Aaron Marcuse-Kubitza about 13 years ago
map | ||
---|---|---|
41 | 41 |
|
42 | 42 |
csv_config = dict(delimiter=',', quotechar='"') |
43 | 43 |
|
44 |
# Load map |
|
45 |
is_xml = True |
|
44 |
# Load map header
|
|
45 |
in_is_xml = True
|
|
46 | 46 |
if uses_map: |
47 | 47 |
import copy |
48 | 48 |
import csv |
49 | 49 |
|
50 | 50 |
import xpath |
51 | 51 |
|
52 |
map_ = {} |
|
53 |
has_types = False # whether outer elements are type containiners |
|
54 |
stream = open(map_path, 'rb') |
|
55 |
reader = csv.reader(stream, **csv_config) |
|
56 |
src, dest = reader.next()[:2] |
|
52 |
map_stream = open(map_path, 'rb') |
|
53 |
map_reader = csv.reader(map_stream, **csv_config) |
|
54 |
src, dest = map_reader.next()[:2] |
|
57 | 55 |
src, sep, src_base = src.partition('/') |
58 |
is_xml = sep != '' |
|
59 |
for row in reader: |
|
60 |
name, path = row[:2] |
|
61 |
if name != '' and path != '': |
|
62 |
if path.startswith('/*s/'): has_types = True # *s for type elem |
|
63 |
path = path.replace('<name>', name) |
|
64 |
map_[name] = xpath.XpathParser(path).parse() |
|
65 |
stream.close() |
|
56 |
in_is_xml = sep != '' |
|
66 | 57 |
|
67 |
# Input datasource to XML tree |
|
68 |
if is_xml: doc = xml.dom.minidom.parse(sys.stdin) |
|
58 |
# Input datasource to XML tree, mapping if needed
|
|
59 |
if in_is_xml: doc = xml.dom.minidom.parse(sys.stdin)
|
|
69 | 60 |
if uses_map: |
70 | 61 |
import xml_xpath |
71 | 62 |
|
63 |
map_ = {} |
|
64 |
has_types = False # whether outer elements are type containiners |
|
65 |
for row in map_reader: |
|
66 |
in_, out = row[:2] |
|
67 |
if out != '': |
|
68 |
if out.startswith('/*s/'): has_types = True # *s for type elem |
|
69 |
out = xpath.parse(out) |
|
70 |
if in_is_xml: pass # TODO: process the mapping |
|
71 |
else: map_[in_] = out |
|
72 |
map_stream.close() |
|
73 |
|
|
72 | 74 |
out_doc = xml.dom.minidom.getDOMImplementation().createDocument(None, |
73 | 75 |
dest, None) |
74 |
if is_xml: raise Exception('XML-XML mapping not supported yet') |
|
76 |
if in_is_xml: raise Exception('XML-XML mapping not supported yet')
|
|
75 | 77 |
else: # input is CSV |
76 | 78 |
reader = csv.reader(sys.stdin, **csv_config) |
77 | 79 |
fieldnames = reader.next() |
Also available in: Unified diff
map: Added more stubs for XML-XML mapping