I'm using Python 3.2's xml.etree.ElementTree
, and am attempting to generate XML like this:
<XnaContent xmlns:data="Model.Data">
<Asset Type="data:MyData">
...
The format is out of my control (it's XNA). Notice that the data
XML namespace is never actually used to qualify elements or attributes, but rather to qualify attribute values to XNA. My code looks like this:
root = Element('XnaContent')
ET.register_namespace('data', 'Model.Data')
asset = SubElement(root, 'Asset', {"Type": "data:MyData"})
However, the output looks like (pretty-printed by me):
<XnaContent>
<Asset Type="data:MyData">
...
</Asset>
</XnaContent>
How can I get the data
XML namespace included in the output?
AttributeError: 'Element' object has no attribute 'nsmap'
, nor isnsmap
mentioned here – Fencesitter