Re: Namespace treatment, cloning and node.supports

Arnaud Le Hors wrote:
> "Dieter Köhler" wrote:
> >
> > Nevertheless we should be more aware of XML-wellformedness, since
> > namespaces are semantic sugar on XML.
> It's not really a matter of XML wellformedness but rather a namespace
> wellformedness. A document with an undeclared namespace prefix in it
> could still be wellformed according to XML 1.0.

But using the DOM2 routines can lead to document trees which are
neither XML wellformed nor namespace wellformed because of not
forbidding double qualified names of attributes in the same element. 
To cite my old example again:

a:= element.setAttributeNS('xyz','x:a','');
b:= element.setAttributeNS('abc','x:a','');

The second line inserts a second attribute node in the element.  If
your application uses a standard traversal of the element.attributes
nodelist for outputting the document tree as an XML document this
would lead to the line:

<element x:a="" x:a="">

which is not wellformed. The same thing happens if your program reads:

a:= element.setAttributeNS('xyz','x:a','');
b:= element.setAttributeNS('abc','y:a','');
b.prefix:= 'x';

The DOM has to specify what to do in such cases:  Raise an exception
or replace attribute a by attribute b, but not admitt both attributes
as attributes of the same element.

> > Your folks can do their
> > serialization by first using the URI as the prefix and then replacing
> > the prefix by a shorter version (Delphi example):
> >
> > element.setAttributeNS('thisIsOurVeryVeryLongURI',
> >                        'thisIsOurVeryVeryLongURI:a',
> >                        'value');
> Actually, in general, this would not work since your URI is most likely
> not going to be a valid XML name.

Your application can escape the invalid characters.

> Whether it's for no gain or not is actually the real question. If you
> stick with the principal that namespace prefixes only are syntactic
> sugar it is a real advantage not to have to bother with them at all and
> completely rely on the serializer to set them and declare them as
> necessary.

If you I stick with XML conformance (and namespaces at all being
*semantic* sugar relative to XML, though of course it has itself a
syntax) it is a real advantage not to have to bother with syntactic
malformed DOM trees.  In an OO view:  If I write a component for doing
something with a DOM tree, e.g. outputting it as an XML document as
mentioned above, with the present version of DOM2 my component cannot
rely on getting wellformed elements -- and this is a real big

> And I would argue that while the DOM implementation doesn't indeed
> enfore namespace wellformedness it doesn't prevent you from doing it at
> the application level.

Again: The problem is XML wellformedness.

BTW: Why is the attributes attribute defined in the nodes interface
and not in the element interface?  No other node type makes use of it.

 Dieter Koehler, M. A. -
 Mittlere Kaulberg 22, D-96049 Bamberg, +49(0)951-5190726
 "": 1000+ Philosophie-Links
 "": Deutsche Philo-Links
 "": Open XML - XML-Komponenten fuer Delphi

Received on Wednesday, 1 March 2000 18:57:36 UTC