This is a really difficult problem to deal with when writing to
stdout/cout. Since XML normalizes everything to \n, we end up having to
normalize back to \r\n on Windows. Sometimes we can do it, and sometimes
we can't.
When writing to a binary file, it's not a problem, since we always open
files in binary mode. But cout is very problematic, because it's a text
stream. It's just another one of those endless Windows vs. Unix problems
that's really difficult to deal with. It's also a huge performance issue,
since we have to examine and escape every character as it's serialized.
If you have any suggestions, I'm all ears...
Dave
"Brian
Quinlan" To: <[EMAIL PROTECTED]>
<BrianQ@Active cc: (bcc: David N Bertoni/CAM/Lotus)
State.com> Subject: Line endings translation
problem
11/20/2001
04:05 PM
Please respond
to xalan-dev
Hi,
I couldn't find a bug filed against problem this so I thought I'd ask the
group if anyone has encountered before. I'm using Xalan 1.1/Xerces 1.4.
It looks like the problem is that XalanOutputStream is being passed string
containing platform line endings in some cases and UNIX line endings in
others. When XalanOutputStream forwards the buffer to cout, cout translates
"\n" => "\r\n" so this problem happens.
Here is my stylesheet (Windows line endings):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="no"/>
<xsl:template match="test">
<xsl:value-of select="text()"/>
</xsl:template>
</xsl:stylesheet>
And source (Window line endings):
<?xml version="1.0" encoding="UTF-8"?>
<test>
This
is
a
test
</test>
Output:
<?xml version="1.0" encoding="UTF-8"?>\r\r\n
This\r\r\n
is\r\r\n
a\r\r\n
test\r\r\n