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, flags=re.MULTILINE)
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:
34 print ("Warning: No mapping for item:" +elem)
38 if "position" in item["attrs"]:
39 if item["attrs"]["position"] == "first":
40 print (item["value"], end="", file=outfile)
43 if not "position" in item["attrs"]:
44 nexthiera = item["items"]
46 print (value, end="", file=outfile)
47 process_file_layer(source, outfile, globals, nexthiera)
50 if "position" in item["attrs"]:
51 if item["attrs"]["position"] == "last":
52 print (item["value"], end="", file=outfile)
53 (ctl,elem, value, attrs) = source.extractElement(ctl)
55 def convert (file, format):
57 source = XmlExtractor()
58 source.openInput(file)
62 tpl = tple.readFile("tpl/"+format+".tpl")
63 globals = tpl["mdoc"][0]["items"]["global"][0]["items"]
64 hierarc = tpl["mdoc"][0]["items"]["hierarchical"][0]["items"]
67 ext = tpl["mdoc"][0]["attrs"]["extension"]
68 outname = re.sub(r"\.xml", "."+ext, file)
69 outfile = open(outname, "w")
70 #print ("hallo", file=outfile)
72 process_file_layer(source, outfile, globals, hierarc)