This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author silverbacknet
Recipients silverbacknet
Date 2013-01-31.02:35:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1359599707.26.0.771342463799.issue17088@psf.upfronthosting.co.za>
In-reply-to
Content
ET reads a default-namespaced (xmnls="whatever") file correctly but won't write it back out.

The error given is:
ValueError: cannot use non-qualified names with default_namespace option

The XML reference is reasonably clear on this:
http://www.w3.org/TR/REC-xml-names/#defaulting
"Default namespace declarations do not apply directly to attribute names;"
"The namespace name for an unprefixed attribute name always has no value."

Therefore, it is not an error to write non-qualified _attribute_ names with a default namespace; they're just considered un-namespaced anyway. The trivial case where a file is read in with a default namespace and written out with the same one should make it obvious:

from xml.etree.ElementTree import *
register_namespace('svg', 'http://www.w3.org/2000/svg')
svg = ElementTree(XML("""
<svg width="12cm" height="4cm" viewBox="0 0 1200 400" xmlns="http://www.w3.org/2000/svg" version="1.1">
<rect x="1" y="1" width="1198" height="398" fill="none" stroke="blue" stroke-width="2" />
</svg>
"""))
svg.write('simple_new.svg',encoding='UTF-8',default_namespace='svg')

Yet this will fail with the error above. By leaving off default_namespace, every element is pointlessly prefixed by 'svg:' in the resulting file, but it does work.
History
Date User Action Args
2013-01-31 02:35:07silverbacknetsetrecipients: + silverbacknet
2013-01-31 02:35:07silverbacknetsetmessageid: <1359599707.26.0.771342463799.issue17088@psf.upfronthosting.co.za>
2013-01-31 02:35:07silverbacknetlinkissue17088 messages
2013-01-31 02:35:06silverbacknetcreate