[gdome] DOM semantics for absent prefix on setAttributeNS qualifiedName



Hi,

The current Gdome returns an exception when you call setAttributeNS with a
namespace but a qualifiedName without a prefix. This is incorrect according to
my reading of the DOM specification...

The code:
  } else if (!strs[1] && namespaceURI != NULL) {     /* there's no ':' */
    prefix = g_strdup("");
    localName = g_strdup(strs[0]);
    if (strcmp (localName, "xmlns"))
      *exc = 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 namespace
URI is already present on the element, its prefix is changed to be the prefix
part of the qualifiedName, and its value is changed to be the value parameter.
This value is a simple string; it is not parsed as it is being set. So any
markup (such as syntax to be recognized as an entity reference) is treated 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 entity
references, the user must create an Attr node plus any Text and EntityReference
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 contains 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 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 "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 the
concatenation of a local name (as defined in this specification), optionally
preceded by a namespace prefix and colon character. See Qualified Names in
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 qualifiedName
does not start with xml. Therefore, the only remaining justification for
raising NAMESPACE_ERR is that the qualifiedName is malformed. But the prefix is
optional, so this doesn't apply either.

It should be sufficient just to remove the check(of course, not all serialisers
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 and not
the DOM implementation).

Best regards,
Andrew Miller


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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]