|
|
|
|
Re: The carriage-return (#xD) character saved as "
\r" [message #427951 is a reply to message #427949] |
Fri, 06 March 2009 13:50 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------010401000603070907050808
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Alexey,
Comments below.
koloale wrote:
> Ed Merks wrote:
>> Guys,
>>
>> I think if you see \r or \n in the serialization it's because you
>> have the two characters \ followed r or n in the string itself. I
>> can't imagine that serialization would ever convert a character into
>> a Java escape sequence. Some other aspect of the logic (not the
>> serialization log) must be doing that...
> Ed, what do mean by 'some other aspect of the logic must be doing that'?
> My code is:
>
> EObject config = EcoreUtil.create(someClass);
> config .eSet(ref, "Hello\r\nWorld");
>
> Resource resource = ;
> resource .getContents().add(config);
>
> ByteArrayOutputStream os = new ByteArrayOutputStream();
> resource.save(os, null);
> assertEquals("Hello
\r\nWorld", os.toString());
>
> So I think it is XMLResourceImpl that convert \r to 
Well yes. Tom already mentioned that and why. If it didn't do that,
what you'd get back when reading it would be the value "Hello\nWorld"
because any XML parser will convert the system's line feed convention to
"\n". The serializer is written so it preserves *exactly *the sequence
of characters you specified. (I thought when you said \r\n you
literally meant those two letter escape sequence appeared in the XML file...
>
> Alexey
--------------010401000603070907050808
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Alexey,<br>
<br>
Comments below.<br>
<br>
koloale wrote:
<blockquote cite="mid:gor856$qmp$1@build.eclipse.org" type="cite">Ed
Merks wrote:
<br>
<blockquote type="cite">Guys,
<br>
<br>
I think if you see \r or \n in the serialization it's because you have
the two characters \ followed r or n in the string itself. I can't
imagine that serialization would ever convert a character into a Java
escape sequence. Some other aspect of the logic (not the serialization
log) must be doing that...
<br>
</blockquote>
Ed, what do mean by 'some other aspect of the logic must be doing
that'?
<br>
My code is:
<br>
<br>
EObject config = EcoreUtil.create(someClass);
<br>
config .eSet(ref, "Hello\r\nWorld");
<br>
<br>
Resource resource = ;
<br>
resource .getContents().add(config);
<br>
<br>
ByteArrayOutputStream os = new ByteArrayOutputStream();
<br>
resource.save(os, null);
<br>
assertEquals("Hello&#xD;\r\nWorld", os.toString());
<br>
<br>
So I think it is XMLResourceImpl that convert \r to &#xD;
<br>
</blockquote>
Well yes. Tom already mentioned that and why. If it didn't do that,
what you'd get back when reading it would be the value "Hello\nWorld"
because any XML parser will convert the system's line feed convention
to "\n". The serializer is written so it preserves <b>exactly </b>the
sequence of characters you specified. (I thought when you said \r\n
you literally meant those two letter escape sequence appeared in the
XML file...<br>
<blockquote cite="mid:gor856$qmp$1@build.eclipse.org" type="cite"><br>
Alexey
<br>
</blockquote>
</body>
</html>
--------------010401000603070907050808--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: The carriage-return (#xD) character saved as "
\r" [message #427960 is a reply to message #427933] |
Fri, 06 March 2009 18:57 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
I imagine the reason the \r still shows up is because the save()
function will turn \n into the current platform's new line characters,
which on windows is \r\n.
So first it was turned into "
\n" by the XML serialization and then
the function turned that last remaining \n into \r\n because that is the
current platform's new line characters.
--
Thanks,
Rich Kulp
|
|
|
Powered by
FUDForum. Page generated in 0.04040 seconds