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

Xerces serializer broken w.r.t. namespaces in Mustang b46

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • jaxp_1.4, 6
    • xml
    • 1.4
    • x86
    • linux, windows_2000

      Compile and run the following:

      ---%<---
      import com.sun.org.apache.xml.internal.serialize.OutputFormat;
      import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
      import java.io.StringReader;
      import javax.xml.parsers.DocumentBuilderFactory;
      import org.w3c.dom.Document;
      import org.xml.sax.InputSource;
      public class TestXercesSerializer {
          public static void main(String[] args) throws Exception {
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              factory.setNamespaceAware(true);
              String xml = "<root xmlns='urn:root'/>";
              Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
              OutputFormat fmt = new OutputFormat();
              fmt.setMethod("xml");
              fmt.setIndenting(true);
              XMLSerializer ser = new XMLSerializer();
              ser.setOutputFormat(fmt);
              ser.setNamespaces(true);
              ser.setOutputByteStream(System.out);
              ser.asDOMSerializer().serialize(doc);
          }
      }
      ---%<---

      Under JDK 1.5, and most Mustang builds, it is OK:

      ---%<---
      java version "1.5.0_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode, sharing)

      <?xml version="1.0" encoding="UTF-8"?>
      <root xmlns="urn:root"/>
      ---%<---
      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b45)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b45, mixed mode, sharing)

      <?xml version="1.0" encoding="UTF-8"?>
      <root xmlns="urn:root"/>
      ---%<---

      But in Mustang b46 it is broken:

      ---%<---
      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b46)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b46, mixed mode, sharing)

      <?xml version="1.0" encoding="UTF-8"?>
      <root xmlns="urn:root" xmlns="urn:root"/>
      ---%<---

      Of course com.sun.org.apache.xml.internal.serialize.XMLSerializer is not public and so this is not a violation of the JAXP spec, but there are surely other clients besides NetBeans' org.openide.xml.XMLUtil.write(...), since there have been a number of bugs in JAXP serialization and until now this class has been more reliable. It ought to be either fixed or deleted or renamed, I think.

            sreddysunw Sunitha Reddy (Inactive)
            jglick Jesse Glick (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: