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

DOM and SAX parsers ignore namespace

XMLWordPrintable

    • 9
    • b22

      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));
              Assert.assertTrue(out.contains("defaultNS"));
          }
          
          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);
          }

            joehw Joe Wang
            joehw Joe Wang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: