[JAXP-19] LSSerializer writes processing instruction at end of document Created: 16/Mar/07  Updated: 19/Mar/07

Status: Open
Project: jaxp
Component/s: www
Affects Version/s: current
Fix Version/s: milestone 1

Type: Bug Priority: Major
Reporter: simplemind Assignee: ndw
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: Windows 2000
Platform: PC

Issuezilla Id: 19


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?>");
//parse XML
Document xmlDocument = null;
InputSource is = new InputSource(new StringReader(xmlString.toString()));
DocumentBuilder docBuilder = null;

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

catch (ParserConfigurationException e)

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

catch (IOException e)

{ e.printStackTrace(); }

DOMImplementation domImpl = docBuilder.getDOMImplementation();
DOMImplementationLS domImplLS = (DOMImplementationLS) domImpl.getFeature("LS",
LSSerializer serializer = domImplLS.createLSSerializer();

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

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.

Comment by Santiago Pericas-Geertsen [ 19/Mar/07 ]

Accepted for further investigation.

Generated at Tue Aug 04 05:37:40 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.