jaxp
  1. jaxp
  2. JAXP-19

LSSerializer writes processing instruction at end of document

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: Windows 2000
      Platform: PC

    • Issuezilla Id:
      19

      Description

      When serializing a XML-Document using LSSerializer (DOMSerializerImpl) a leading
      processing-instruction (firstChild of the Document) appears at the end of the
      serialized Document.
      This issue occours using jre 1.4.2 (I checked it with different releases
      (1.4.2_01, 1.4.3_13 and one or two more)) and JAXP 1.4.
      This issue does NOT appear with jre 1.5 or JAXP 1.3

      I used Eclipse 3.2.1 for the tests and the endorsed standard override mechanism.

      Here is a sample-class for evaluating:

      import java.io.IOException;
      import java.io.StringReader;

      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.ParserConfigurationException;

      import org.w3c.dom.DOMImplementation;
      import org.w3c.dom.Document;
      import org.w3c.dom.ls.DOMImplementationLS;
      import org.w3c.dom.ls.LSSerializer;
      import org.xml.sax.InputSource;
      import org.xml.sax.SAXException;

      public class SerializeTest {

      public SerializeTest() {
      }

      public static void main(String [] args)

      { SerializeTest serializeTest = new SerializeTest(); serializeTest.serializePI(); }

      public void serializePI() {
      //create XML as String
      StringBuffer xmlString = new StringBuffer();
      xmlString.append("<?xml version=\"1.0\" encoding=\"UTF-16\"?>");
      xmlString.append("<?processingTarget processingData?>");
      xmlString.append("<Elements>");
      xmlString.append("<Element>Text1</Element>");
      xmlString.append("</Elements>");
      //parse XML
      Document xmlDocument = null;
      InputSource is = new InputSource(new StringReader(xmlString.toString()));
      DocumentBuilder docBuilder = null;
      try

      { docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); }

      catch (ParserConfigurationException e)

      { e.printStackTrace(); }
      try { xmlDocument = docBuilder.parse(is); } catch (SAXException e) { e.printStackTrace(); }

      catch (IOException e)

      { e.printStackTrace(); }

      //serialize
      DOMImplementation domImpl = docBuilder.getDOMImplementation();
      DOMImplementationLS domImplLS = (DOMImplementationLS) domImpl.getFeature("LS",
      "3.0");
      LSSerializer serializer = domImplLS.createLSSerializer();
      System.out.println(serializer.writeToString(xmlDocument));
      }
      }

      The output of the last System.out when using JAXP 1.3 is:
      <?xml version="1.0" encoding="UTF-16"?>
      <?processingTarget processingData?><Elements><Element>Text1</Element></Elements>

      The JAXP 1.4 - output is:
      <?xml version="1.0" encoding="UTF-16"?>
      <Elements><Element>Text1</Element></Elements><?processingTarget processingData?>

      I am interested in this functionality because I want to create a xml-stylesheet

      • processing instruction, which surely must be between the prolog and the
        root-element.

      I tested this issue with different JREs and configurations.
      Additionally I spent a lot of time searching for solutions but I could not find
      anything on this site nor at sun.com or anywhere else, so I am quiet sure this
      is a defect.

        Activity

        simplemind created issue -
        kenaiadmin made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 19 46703

          People

          • Assignee:
            ndw
            Reporter:
            simplemind
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: