I'm trying to create an XML file so that it has the following skeleton, preferably using the xml.etree modules in Python 2.7:
<?xml version="1.0"?>
<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" thing1="this" thing2="that">
....
<somedata bar="1">
<moredata whatsit="42"></moredata>
</somedata>
....
</foo>
It's the "foo ...." line that vexes me. I tried using nsmap for bringing in xsi and xsd, but that led to a "cannot serialize" error.
I could construct or otherwise hack that line's text to be exactly as I want it, but I'd like to learn to do this programmatically using xml.etree (pulling in an external library is not preferable in this situation).
I'd think this is a common pattern but I'm just not finding it anywhere for Python and etree.
xml.etree
is too weak for that. – Alkalosis