Re: DOM semantics for absent prefix on setAttributeNS qualifiedName

Andrew Miller <[email protected]> Wed, 22 Feb 2006 10:05:38 +1300
Newsgroups gmane.comp.gnome.gdome
Message-ID <[email protected]>
Quoting Paolo Casarini <[email protected]>:

> Hi Andrew,
>
>   checking the code of the gdome_xml_el_setAttributeNS function wrt to
> DOM2 semantics I notice a bug, but it is not the one you have
> described.
>
>
> On Monday, February 20, 2006, 11:26:00 PM, Andrew Miller wrote:
> > The current Gdome returns an exception when you call setAttributeNS w=
ith a
> > namespace but a qualifiedName without a prefix. This is incorrect acc=
ording
> to
> > my reading of the DOM specification...
>
> > The code:
> >   } else if (!strs[1] && namespaceURI !=3D NULL) {     /* there's no =
':' */
> >     prefix =3D g_strdup("");
> >     localName =3D g_strdup(strs[0]);
> >     if (strcmp (localName, "xmlns"))
> >       *exc =3D GDOME_NAMESPACE_ERR;
>
> If there is no prefix the exception is thrown only if the
> qualifiedName is equal to "xmlns".

Except that strcmp returns 0 if the strings are equal, and non-zero other=
wise.
So if that was your intention, the logic is reversed(i.e. the current che=
ck
returns an exception only if localName is not equal to xmlns).

>
> > The text of the DOM Level 2 specification:
> >
> -----------------------------------------------------------------------=
-------
> > [...]
> >     NAMESPACE_ERR: Raised if the qualifiedName is malformed, if the
> > qualifiedName has a prefix and the namespaceURI is null, if the
> qualifiedName
> > has a prefix that is "xml" and the namespaceURI is different from
> > "http://www.w3.org/XML/1998/namespace", or if the qualifiedName is "x=
mlns"
> and
> > the namespaceURI is different from "http://www.w3.org/2000/xmlns/".
> > [...]
>
> The bug I notice is that now the exception is thrown even if the
> namespaceURI is equal to "http://www.w3.org/2000/xmlns/" and this
> incorrect.
>
> Do you agree?

I think that interpretation is correct, although I believe foo:xmlns=3D"s=
omething"
is legitimate, so you have to compare the qualifiedName, not the localNam=
e.

So something like
if (!strcmp(qualifiedName, "xmlns") &&
    !strcmp(namespaceURI, "http://www.w3.org/2000/xmlns/"))
  *exc =3D GDOME_NAMESPACE_ERR;

Best regards,
Andrew Miller


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.