You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Brian Minchau (JIRA)" <xa...@xml.apache.org> on 2005/03/05 07:43:48 UTC

[jira] Commented: (XALANJ-2075) Transformation using StreamResult and DOMSource with text nodes containing "\r\n" results in " \r\n"

     [ http://issues.apache.org/jira/browse/XALANJ-2075?page=comments#action_60249 ]
     
Brian Minchau commented on XALANJ-2075:
---------------------------------------

Tim,
when the serializer gets \r\n as something it needs to write out it does two things.

The \n is turned into the end of line sequence. This could change in the future, but if you look at the serializer code it calls System.getProperty("line.separator"), and what ever that returns, is what it writes out rather than \n to a flat XML file.  I mean XML file here, not a document. An XML file is a sequence of characters.

The \r is written out as &#13; to a flat XML file. This is so that when an XML parser reads this file back in it is turned into a \r again, with no distortion of information, otherwise it might accidentally be normalized way
( see http://www.w3.org/TR/REC-xml#sec-line-ends ).

So in your case \r is turned into &#13; and \n is turned into \r\n on Windows.

If you feed the serializer \r it will be turned into &#13;. Though not an official API on the Xalan serialzier, you could call System.setProperty("line.separator","\n"); to alter what the serializer will pick up from that property.

Sending output to a DOM is completely different, all of these character changes on output are when writing to a flat file.

I'm afraid the serializer is working as designed.


> Transformation using StreamResult and DOMSource with text nodes containing "\r\n" results in "&#13;\r\n"
> --------------------------------------------------------------------------------------------------------
>
>          Key: XALANJ-2075
>          URL: http://issues.apache.org/jira/browse/XALANJ-2075
>      Project: XalanJ2
>         Type: Bug
>   Components: Serialization
>     Versions: 2.6
>  Environment: Windows 2000 SP4, Sun JDK 1.4.2_05, xalan-j 2.6.0, xerces-j 2.6.2
>     Reporter: Tim Chao

>
> Transformation using StreamResult and DOMSource with text nodes containing "\r\n" results in "&#13;\r\n"
> The following code snippet transform the DOM:
>   <textarea>line1\r\nline2\r\nline3</textarea>
> into:
>   <textarea>line1&#13;\r\nline2&#13;\r\nline3</textarea>
> [Transforming into a DOMResult works as expected (no extraneous &#13;'s).]
> Code snippet (using DOMSource and StreamResult):
> public void reproduceBySerialization() {
>     String outputFile = "result";
>     OutputStream ostream = null;
>     try {
>         ostream = new BufferedOutputStream(new FileOutputStream(outputFile));
>         Result result = new StreamResult(ostream);
>         // create dom of:
>         // <textarea>line1\r\nline2\r\nline3</textarea>
>         Document doc = DocumentBuilderFactory
>                         .newInstance()
>                         .newDocumentBuilder()
>                         .newDocument();
>         Node parent = doc.createElement("textarea");
>         doc.appendChild(parent);
>         Node child = doc.createTextNode("line1\r\nline2\r\nline3");
>         parent.appendChild(child);
>         Source input = new DOMSource(doc);
>         Transformer transformer = TransformerFactory
>                                     .newInstance()
>                                     .newTransformer();
>         transformer.transform(input, result);
>     } catch (Exception e) {
>         e.printStackTrace();
>     } finally {
>         if (ostream != null) {
>             try {
>                 ostream.flush();
>                 ostream.close();
>             } catch (IOException e) {
>                 e.printStackTrace();
>             }
>         }
>     }
> }

-- 
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
-
If you want more information on JIRA, or have a bug to report 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