Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2361

DOM to stream conversion fails on prefix beginning like "xmlConfiguration"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • 2.7
    • None
    • Serialization
    • None
    • PatchAvailable

    Description

      Here is a simple test case to reproduce the problem:

      code
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setNamespaceAware(true);
      TransformerFactory tf = TransformerFactory.newInstance();

      String src = "<root><xmlConfiguration:xmlConfiguration xmlns:xmlConfiguration=\"urn:configuration\" /></root>";
      Document doc = dbf.newDocumentBuilder().parse(new ByteArrayInputStream(src.getBytes()));
      ByteArrayOutputStream res = new ByteArrayOutputStream();
      tf.newTransformer().transform(new DOMSource(doc), new StreamResult(res));
      System.out.println(res);
      dbf.newDocumentBuilder().parse(new ByteArrayInputStream(res.toByteArray()));
      code

      The last line throws an exception, because the xmlns:xmlConfiguration attribute has been lost.

      While debugging, I found that the problem comes from http://svn.apache.org/repos/asf/xalan/java/trunk/src/org/apache/xml/serializer/NamespaceMappings.java,
      line 228:

      code
      // Prefixes "xml" and "xmlns" cannot be redefined
      if (prefix.startsWith(XML_PREFIX))

      { return false; }
      code

      It seems this test is wrong, and it should be

      code
      // Prefixes "xml" and "xmlns" cannot be redefined
      if (prefix.equals("xml") || prefix.equals("xmlns")
      { return false; }

      code

      Attachments

        1. XALANJ-2361.patch
          1 kB
          Guillaume Nodet

        Activity

          People

            minchau@ca.ibm.com Brian Minchau
            gnodet Guillaume Nodet
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: