[issue17088] ElementTree incorrectly refuses to write attributes without namespaces when default_namespace is used

Gene Wood report at bugs.python.org
Mon Apr 14 05:17:19 CEST 2014


Gene Wood added the comment:

One workaround to this is described here : http://stackoverflow.com/a/4999510/168874

It involves prefixing all of the elements with the namespace like this :

    from xml.etree import ElementTree as ET
    
    # build a tree structure
    root = ET.Element("{http://www.company.com}STUFF")
    body = ET.SubElement(root, "{http://www.company.com}MORE_STUFF")
    body.text = "STUFF EVERYWHERE!"
    
    # wrap it in an ElementTree instance, and save as XML
    tree = ET.ElementTree(root)
    
    tree.write("page.xml",
               xml_declaration=True,encoding='utf-8',
               method="xml",default_namespace='http://www.company.com')

----------
nosy: +gene_wood

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17088>
_______________________________________


More information about the Python-bugs-list mailing list