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

XSLT Identity transform fails for StreamSource and StAXResult

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6u10
    • Fix Version/s: None
    • Component/s: xml
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_10"
      Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
      Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      Trying to convert text/xml to the StAXEvents through the Identity xslt transform fails. For illustraction see the attached source.

      Putting simple XML with a prefixed element:
      <ns:elem xmlns:ns='http://some.com&#39;/>

      results in the following XMLEvents:
      <?xml version="1.0" encoding='UTF-8'?>
      <['http://some.com&#39;]:ns:elem xmlns:ns='ns' xmlns:xmlns='http://some.com&#39;>
      </['http://some.com&#39;]:ns:elem>
      ENDDOCUMENT

      Note the invalid namespace context here:
      xmlns:ns='ns' xmlns:xmlns='http://some.com&#39;

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached program.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The XML identical to the original is expected to be printed.
      ACTUAL -
      Exception while transforming.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      ERROR: 'prefix ns has been already bound to http://some.com. Rebinding it to ns is an error'
      Exception in thread "main" javax.xml.transform.TransformerException: javax.xml.stream.XMLStreamException: prefix ns has been already bound to http://some.com. Rebinding it to ns is an error
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
      at XercesTest.main(XercesTest.java:83)
      Caused by: javax.xml.stream.XMLStreamException: prefix ns has been already bound to http://some.com. Rebinding it to ns is an error
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2StAXEventWriter.startElement(Unknown Source)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.closeStartTag(Unknown Source)
      at com.sun.org.apache.xml.internal.serializer.ToSAXHandler.flushPending(Unknown Source)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.endElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
      ... 3 more
      ---------
      javax.xml.stream.XMLStreamException: prefix ns has been already bound to http://some.com. Rebinding it to ns is an error
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2StAXEventWriter.startElement(Unknown Source)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.closeStartTag(Unknown Source)
      at com.sun.org.apache.xml.internal.serializer.ToSAXHandler.flushPending(Unknown Source)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.endElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
      at XercesTest.main(XercesTest.java:83)
      ---------
      javax.xml.stream.XMLStreamException: prefix ns has been already bound to http://some.com. Rebinding it to ns is an error
      at com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeNamespace(Unknown Source)
      at com.sun.xml.internal.stream.writers.XMLEventWriterImpl.add(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2StAXEventWriter.startElement(Unknown Source)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.closeStartTag(Unknown Source)
      at com.sun.org.apache.xml.internal.serializer.ToSAXHandler.flushPending(Unknown Source)
      at com.sun.org.apache.xml.internal.serializer.ToXMLSAXHandler.endElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
      at XercesTest.main(XercesTest.java:83)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.ByteArrayInputStream;

      import javax.xml.stream.XMLEventWriter;
      import javax.xml.stream.XMLOutputFactory;
      import javax.xml.transform.TransformerFactory;
      import javax.xml.transform.stax.StAXResult;
      import javax.xml.transform.stream.StreamSource;

      public class XercesTest {

      public static void main(String[] args) throws Exception {
      String xml = "<ns:elem xmlns:ns='http://some.com&#39;/>";
      TransformerFactory xformFactory = TransformerFactory.newInstance();
      StreamSource src = new StreamSource(new ByteArrayInputStream(xml.getBytes()));
      XMLEventWriter ew = XMLOutputFactory.newInstance().createXMLEventWriter(System.out);
      StAXResult result = new StAXResult(ew);
      xformFactory.newTransformer().transform(src, result);
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use of 'stax-utils' instead.

        Attachments

          Activity

            People

            • Assignee:
              joehw Joe Wang
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Imported:
                Indexed: