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

DOM and SAX parsers ignore namespace

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • 9, 10, 11, 12
    • 13
    • xml
    • 9
    • b22

    Description

      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);
          }

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: