ElementTree Namespace Prefixes
jzgoda at gazeta.usun.pl
Sun Jun 12 20:58:37 CEST 2005
Chris Spencer napisał(a):
> Given xml with no namespaces, Elementtree works perfectly. However, if
> you give the root tag an xmlns attribute, Elementtree relabels all child
> nodes with it's own prefix, completely defeating the purpose of the
> default namespace. In my opinion, this is unacceptable behavior.
There is no functional difference between default namespace and "normal"
namespace. Replacing "default" with "normal" has no effect for document
processing (namespace doesn't change, only prefix), although it looks
differently for humans. Anyway, XML is for machines, not for humans.
> If an XML parser reads in and then writes out a document without having
> altered it, then the new document should be the same as the original.
> With Elementtree this isn't so. Lundh apparently believes he knows
> better than you and I on how our namespaces should be represented.
No, this is perfectly valid behaviour. Go, see spec.
> It's a shame the default ns behavior in Elementtree is in such a poort
> staten. I'm surprised no one's forked Elementtree solely to fix this issue.
There is at least one ElementTree API implementation that retains
prefixes, lxml.ETree. Go google for it.
http://jpa.berlios.de/ | http://www.zgodowie.org/
More information about the Python-list