Message181005
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. |
|
Date |
User |
Action |
Args |
2013-01-31 02:35:07 | silverbacknet | set | recipients:
+ silverbacknet |
2013-01-31 02:35:07 | silverbacknet | set | messageid: <1359599707.26.0.771342463799.issue17088@psf.upfronthosting.co.za> |
2013-01-31 02:35:07 | silverbacknet | link | issue17088 messages |
2013-01-31 02:35:06 | silverbacknet | create | |
|