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

New methods for creating DOM and SAX factories with Namespace support

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 13
    • xml
    • None
    • minimal
    • No risk. New methods only.
    • Java API
    • SE

      Summary

      Add newInstance methods that turn on Namespace support by default

      Problem

      When the XML Namespace support was introduced in Java SE 1.4, it made the default setting of NamespaceAware feature false in order to maintain backward compatibility. To enable Namespace support, a method "setNamespaceAware" has to be called as demonstrated below:

      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      // turn on namespace support
      dbf.setNamespaceAware(true);
      DocumentBuilder db = dbf.newDocumentBuilder(); 

      The problem is that users are often time not realizing or forgetting that the default setting for DOM and SAX is not Namespace aware and attempt to create a parser with a method chain such as:

      DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 

      and then encounter processing errors such as missing namespaces or not being able to read namespace (e.g. a call to lookupNamespaceURI returns null).

      While such issues can be resolved by setting Namespace aware, it is nonetheless a nuisance to the development process.

      Solution

      Namespace support has been in the Java SE since 1.4. Since then, XML Namespace has become a norm for XML development. Having a parser that supports Namespace by default is long overdue and would be more user-friendly.

      In the feature request, we would like to propose adding newInstance methods that shall turn on Namespace by default. The benefit is not only eliminating the trouble users may encounter as described in the problem section, but also reminding users that the old/existing corresponding methods would create factory instances that have Namespace support turned off.

      The new methods add "NS" for Namespace as a prefix to the existing methods. With these new methods, users would be able to a chained method to create a parser with Namespace support, for DOM:

      DocumentBuilder db = DocumentBuilderFactory.newNSInstance().newDocumentBuilder(); 

      and for SAX:

      SAXParser sp = SAXParserFactory.newNSInstance().newSAXParser();

      Specification

      Specdiff: http://cr.openjdk.java.net/~joehw/jdk13/8219692/specdiff_02/overview-summary.html

            joehw Joe Wang
            joehw Joe Wang
            Lance Andersen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: