I am creating a xml file. i am done with the root element creation and i am able to define xml declaration. But i need to create anther tag, which looks like
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:TalendProperties="http://www.talend.org/properties">
# i am unable to replicate the above
### some subelements..
</xmi:XMI>
i am done with adding xmlns URIs, but unable to get the xmi:version="2.0".
I am not familiar with XML, so getting confused, read about namespace and all, not quite getting it. Can somebody show me how to do that or share a related weblink. That woul dbe great help. Because i found mostly the XML parsing stuff on internet but very few resource on XML generaton.
xmlns_uris_dict = {'xmi':'http://..', 'subprocess':'http://xyz...'}
root = ET.Element("talendfile:ProcessType")
ET.register_namespace('xmi', 'version="2.0"') # This part gives a wrong presentation.
# i am able to add URIs here
for prefix, uri in xmlns_uris_dict.items():
root.attrib['xmlns:' + prefix] = uri
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…