[4suite] DomWriter problem
Alexandre Fayolle
alf at logilab.com
Thu Sep 21 10:25:47 MDT 2000
On Thu, 21 Sep 2000, Uche Ogbuji wrote:
> When you submitted DomWriter.py, it was correct according to 4DOM at
> that time. The problem is that 4DOM was not correct according to the
> very latest DOM. The May DOM CR changed the entire mechanism for
> namespace declaration attributes.
Arg, I'll have to check this out.
> Your code should look something like this:
>
> from xml.dom import XMLNS_NAMESPACE
> for prefix in extraNss.keys():
> if prefix:
> new_element.setAttributeNS(XMLNS_NAMESPACE,
> 'xmlns:'+prefix,
> extraNss[prefix])
> else:
> new_element.setAttributeNS(XMLNS_NAMESPACE,
> 'xmlns',
> extraNss[''])
>
> Please confirm that this works for you.
It does not. :o(
I still get the NAMESPACE_ERR. I checked in Document.createAttributeNS,
and it seems there is an error here: the error is raised on line 391,
before 4Dom has a chance to check if localName is 'xmlns'
proposed patch:
Document.py
def createAttributeNS(self, namespaceURI, qualifiedName):
if not g_namePattern.match(qualifiedName):
trace("Create Attribute Failed, Invalid Character: %s" % c)
raise DOMException(INVALID_CHARACTER_ERR)
Attr = implementation._4dom_fileImport('Attr').Attr
(prefix, localName) = SplitQName(qualifiedName)
if prefix == 'xml':
if namespaceURI and namespaceURI != XML_NAMESPACE:
raise DOMException(NAMESPACE_ERR)
- if (not namespaceURI and prefix) or (not prefix and
namespaceURI):
- raise DOMException(NAMESPACE_ERR)
if localName == 'xmlns':
a = Attr(self, qualifiedName, XMLNS_NAMESPACE, 'xmlns',
prefix)
else:
+ if (not namespaceURI and prefix) or (not prefix and
namespaceURI):
+ raise DOMException(NAMESPACE_ERR)
a = Attr(self, qualifiedName, namespaceURI, prefix, localName)
trace("Create AttributeNS %s"%str((qualifiedName, namespaceURI,
prefix, localName)))
return a
Element.py (the suppressed lines are not required sinc the exception is
thrown in Document.createAttributeNS):
def setAttributeNS(self, namespaceURI, qualifiedName, value):
if not g_namePattern.match(qualifiedName):
trace('Create Atribute Failed, Invalid character')
raise DOMException(INVALID_CHARACTER_ERR)
att = self.ownerDocument.createAttributeNS(namespaceURI,
qualifiedName)
(prefix, local) = ext.SplitQName(qualifiedName)
- if prefix == 'xml':
- if namespaceURI and namespaceURI != XML_NAMESPACE:
- raise DOMException(NAMESPACE_ERR)
- if (not namespaceURI and prefix) or (not prefix and
namespaceURI):
- raise DOMException(NAMESPACE_ERR)
att.nodeValue = value
self.setAttributeNodeNS(att)
return
Using this patch, however, all the elements I get look a bit weird:
<memory xmlns='xsl' />
Is still have to check the new spec, but to me, this means that memory is
in the xsl namespace. Please correct me if I'm wrong.
> Also, do you mind putting
> together a small test suite for DOMWriter that we can incorporate into
> our code? This will make sure we don't overlook it again.
I'll do this ASAP, probably tomorow morning.
--
Alexandre Fayolle
http://www.logilab.com - "Mais o est donc Ornicar ?" -
LOGILAB, Paris (France).
More information about the 4suite
mailing list