DOM semantics for absent prefix on setAttributeNS qualifiedName
Andrew Miller <[email protected]> Tue, 21 Feb 2006 11:26:00 +1300
| Newsgroups | gmane.comp.gnome.gdome |
|---|---|
| Message-ID | <[email protected]> |
Hi,
The current Gdome returns an exception when you call setAttributeNS with =
a
namespace but a qualifiedName without a prefix. This is incorrect accordi=
ng 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;
The text of the DOM Level 2 specification:
-------------------------------------------------------------------------=
-----
setAttributeNS introduced in DOM Level 2
Adds a new attribute. If an attribute with the same local name and na=
mespace
URI is already present on the element, its prefix is changed to be the pr=
efix
part of the qualifiedName, and its value is changed to be the value param=
eter.
This value is a simple string; it is not parsed as it is being set. So an=
y
markup (such as syntax to be recognized as an entity reference) is treate=
d as
literal text, and needs to be appropriately escaped by the implementation=
when
it is written out. In order to assign an attribute value that contains en=
tity
references, the user must create an Attr node plus any Text and EntityRef=
erence
nodes, build the appropriate subtree, and use setAttributeNodeNS or
setAttributeNode to assign it as the value of an attribute.
HTML-only DOM implementations do not need to implement this method.
Parameters
namespaceURI of type DOMString
The namespace URI of the attribute to create or alter.
qualifiedName of type DOMString
The qualified name of the attribute to create or alter.
value of type DOMString
The value to set in string form.
Exceptions
DOMException
INVALID_CHARACTER_ERR: Raised if the specified qualified name contain=
s an
illegal character.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NAMESPACE_ERR: Raised if the qualifiedName is malformed, if the
qualifiedName has a prefix and the namespaceURI is null, if the qualified=
Name
has a prefix that is "xml" and the namespaceURI is different from
"http://www.w3.org/XML/1998/namespace", or if the qualifiedName is "xmlns=
" and
the namespaceURI is different from "http://www.w3.org/2000/xmlns/".
No Return Value
-------------------------------------------------------------------------=
--
The definition of a qualified name:
-------------------------------------------------------------------------=
--
qualified name
A qualified name is the name of an element or attribute defined as th=
e
concatenation of a local name (as defined in this specification), optiona=
lly
preceded by a namespace prefix and colon character. See Qualified Names i=
n
Namespaces in XML [Namespaces].
-------------------------------------------------------------------------=
----
If gdome is to conform to a specification, it can only raise a NAMESPACE_=
ERR if
one of the reasons listed applies. namespaceURI is not NULL, and qualifie=
dName
does not start with xml. Therefore, the only remaining justification for
raising NAMESPACE_ERR is that the qualifiedName is malformed. But the pre=
fix is
optional, so this doesn't apply either.
It should be sufficient just to remove the check(of course, not all seria=
lisers
will work correctly if you serialise the output with a null prefix but a
non-null namespace, but I believe that becomes a bug in the serialiser an=
d not
the DOM implementation).
Best regards,
Andrew Miller
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.