Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6903561

Namespace URI should be empty string for empty/no namespace


    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Future Project
    • Affects Version/s: 7
    • Fix Version/s: 5.0
    • Component/s: xml
    • Labels:


      According to 6.2 Namespace Defaulting [1] in Namespace in XML 1.0, "The attribute value in a default namespace declaration MAY be empty. This has the same effect, within the scope of the declaration, of there being no default namespace. "

      The Xerces impl however, convert empty string to null as in the following code:
      protected void scanAttribute(XMLAttributesImpl attributes)
                        // declare prefix in context
      line 554: boolean declared = fNamespaceContext.declarePrefix(prefix, uri.length() != 0 ? uri : null);

      Similarly, namespaceURI for attributes in no namespace is also returned as null.

      From the spec, these are wrong because the spec stated clearly at section 3 Declaring Namespaces that the attribute's normalized value must be either a URI reference or an empty string. "null" to me is invalid.

      The Java API has inconsistent definition among DOM, SAX and StAX. SAX correctly defined that an empty string meant no Namespace in for example the startElement callback method of the ContentHandler. DOM however, used "null", the getAttributeNodeNS of the Element API states that "Per [XML Namespaces] , applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace." This is wrong because the XML Namespaces specified empty string, not null.

      StAX API also implied the URI may be null. For example, StreamReader's getNamespaceURI states that it should return the URI bound to this element's prefix, the default namespace, or null. And yet, the writeEmptyElement or writeStartElement(namespaceURI, localName) states that namespaceURI can not be null.

      To fix the API, we would need another CCC approval to correct the Java API for DOM and StAX, and we would have to fix in several places. Since it's an edge case and no report on it yet, this CR is filed only for future releases.




            • Assignee:
              joehw Joe Wang
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: