JDK-8219692 : DOM and SAX parsers ignore namespace
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxp
  • Affected Version: 9,10,11,12
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-02-26
  • Updated: 2023-10-27
  • Resolved: 2019-05-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 13
13 b22Fixed
Related Reports
CSR :  
Relates :  
Sub Tasks
JDK-8224556 :  
Starting from JDK 9, LSSerializer skips the default namespace. The following test fails in JDK 9 and later:

    public void testDefaultNS() throws Exception {
        String xml = "<a "
                + "xmlns=\"http://openjdk_java_net/xml/defaultNS\" "
                + "xmlns:p1=\"http://openjdk_java_net/xml/serializer/\">"
                + "<b>in default namespace</b></a>";
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        LSSerializer ls = getSerializer(db);
        String out = ls.writeToString(getDoc(db, xml));
    private LSSerializer getSerializer(DocumentBuilder db) throws Exception {
        DOMImplementationLS di = (DOMImplementationLS) db.getDOMImplementation();
        return di.createLSSerializer();
    private Document getDoc(DocumentBuilder db, String xml) throws Exception {
        InputSource is = new InputSource(new StringReader(xml));
        return db.parse(is);

URL: http://hg.openjdk.java.net/jdk/jdk/rev/6bd29804ace0 User: joehw Date: 2019-05-21 21:56:26 +0000

Since JDK 9, Xerces has moved to use Xalan based DOM L3 serializer which enforces the Namespace Support requirement. Setting NamespaceAware therefore would resolve the above issue: DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance(); // fail without namespace support dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); To make it easier, and also help raise the awareness of the default setting, new methods will be introduced so that the above can be achieved as follows. Note the new method adds "NS" as prefix to stand for NamespaceAware. DocumentBuilder db = DocumentBuilderFactory.newDefaultNSInstance().newDocumentBuilder();