7 from mutil.XmlExtractor import XmlExtractor
8 from mutil import XmlExtractor as XMLE
11 def outfirst(outfile, tpllayer, attrs, value):
13 ostr = tpllayer["value"]
15 ostr = re.sub(r"\$value", value, ostr)
16 print (ostr, end="", file=outfile)
18 def outlast(outfile, tpllayer, attrs, value):
22 def process_file_layer(source, outfile, globals, hierarc):
25 (ctl,elem, value, attrs) = source.extractElement(XMLE.EC_BEG)
26 while ctl != XMLE.EC_END:
31 nexthiera = hierarc[elem]["items"]
35 print ("Warning: No mapping for item:" +elem)
37 outfirst(outfile, item, attrs, value)
38 process_file_layer(source, outfile, globals, nexthiera)
40 outlast(outfile, item, attrs, value)
41 (ctl,elem, value, attrs) = source.extractElement(ctl)
43 def convert (file, format):
45 source = XmlExtractor()
46 source.openInput(file)
50 tpl = tple.readFile("tpl/"+format+".tpl")
51 globals = tpl["mdoc"]["items"]["global"]["items"]
52 hierarc = tpl["mdoc"]["items"]["hierarchical"]["items"]
55 ext = tpl["mdoc"]["attrs"]["extension"]
56 outname = re.sub(r"\.xml", "."+ext, file)
57 outfile = open(outname, "w")
58 #print ("hallo", file=outfile)
60 process_file_layer(source, outfile, globals, hierarc)