Issue Details (XML | Word | Printable)

Key: JAXP-19
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: ndw
Reporter: simplemind
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
jaxp

LSSerializer writes processing instruction at end of document

Created: 16/Mar/07 05:07 PM   Updated: 19/Mar/07 08:14 AM
Component/s: www
Affects Version/s: current
Fix Version/s: milestone 1

Time Tracking:
Not Specified

Environment:

Operating System: Windows 2000
Platform: PC


Issuezilla Id: 19
Tags:
Participants: ndw, Santiago Pericas-Geertsen and simplemind


 Description  « Hide

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.



Santiago Pericas-Geertsen added a comment - 19/Mar/07 08:14 AM

Accepted for further investigation.