You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Michael Glavassevich (JIRA)" <xa...@xml.apache.org> on 2006/11/15 08:05:37 UTC
[jira] Commented: (XALANJ-2338) DOM Level 3 serializer APIs give
incorrect encoding (UTF-16)
[ http://issues.apache.org/jira/browse/XALANJ-2338?page=comments#action_12449922 ]
Michael Glavassevich commented on XALANJ-2338:
----------------------------------------------
The encoding is supposed to be UTF-16. See http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/load-save.html#LS-LSSerializer-writeToString.
> DOM Level 3 serializer APIs give incorrect encoding (UTF-16)
> ------------------------------------------------------------
>
> Key: XALANJ-2338
> URL: http://issues.apache.org/jira/browse/XALANJ-2338
> Project: XalanJ2
> Issue Type: Bug
> Components: Serialization
> Affects Versions: Latest Development Code
> Reporter: Brian Minchau
>
> When the following testcase is run with Xerces (with a patch to use the new DOM Level 3 APIs under the covers) the output encoding shows as UTF-16, but should probably be UTF-8.
> Here is the testcase:
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import org.apache.xml.serializer.DOM3Serializer;
> import org.apache.xml.serializer.OutputPropertiesFactory;
> import org.apache.xml.serializer.Serializer;
> import org.apache.xml.serializer.SerializerFactory;
> import org.w3c.dom.DOMConfiguration;
> import org.w3c.dom.Document;
> import org.w3c.dom.bootstrap.DOMImplementationRegistry;
> import org.w3c.dom.ls.DOMImplementationLS;
> import org.w3c.dom.ls.LSSerializer;
> public class TestDOM3 {
> public static void main(String args[]) throws Exception {
> TestDOM3 test = new TestDOM3();
> System.out.println(test.testDOM3LS());
> }
>
> public Document getDocument() throws Exception {
> Document doc = null;
> DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
> DocumentBuilder builder = factory.newDocumentBuilder();
> byte[] bytes = "<parent><child/></parent>".getBytes();
> java.io.InputStream is = new java.io.ByteArrayInputStream(bytes);
> doc = builder.parse(is);
> return doc;
> }
> public String testDOM3LS() throws Exception {
> Document doc = getDocument();
> System.setProperty(DOMImplementationRegistry.PROPERTY,
> "org.apache.xerces.dom.DOMImplementationSourceImpl");
> DOMImplementationLS impl = (DOMImplementationLS) DOMImplementationRegistry
> .newInstance().getDOMImplementation("LS");
> LSSerializer writer = impl.createLSSerializer();
> DOMConfiguration config = writer.getDomConfig();
> config.setParameter("format-pretty-print", Boolean.TRUE);
> return writer.writeToString(doc);
> }
>
> }
> Here is the output:
> <?xml version="1.0" encoding="UTF-16"?><parent><child/></parent>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org