Skip to main content



      Home
Home » Modeling » EMF » The carriage-return (#xD) character saved as "
\r"
The carriage-return (#xD) character saved as "
\r" [message #427929] Fri, 06 March 2009 05:28 Go to next message
Eclipse UserFriend
Hello!

When I save resource using Default XML serialization and in that
resource some element with value e.g. "Hello\r\nWorld!" is contained, I
get XML like that: "Hello
\r\n". I know that 
 is XML entity
representin Unicode character for CR, but why it's saved twice as xml
entity and as '\r' char? Can you clarify this point: how actually save
CR character correctly?

Thank you,
Alexey
Re: The carriage-return (#xD) character saved as "
\r" [message #427933 is a reply to message #427929] Fri, 06 March 2009 05:58 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

Well the reason that \r is saved as an escape sequence is that when
reading XML-Spec it states that \r\n is normalized to \n when parsing
XML. So when reading back the file using an standard compilant
XML-Parser the resulting string is:

"Hello\r\n"

because \r\n is normalized to \n. Why the \r is kept when serializing is
something I can't tell you but at least it should make no difference to you.

Tom

koloale schrieb:
> Hello!
>
> When I save resource using Default XML serialization and in that
> resource some element with value e.g. "Hello\r\nWorld!" is contained, I
> get XML like that: "Hello
\r\n". I know that 
 is XML entity
> representin Unicode character for CR, but why it's saved twice as xml
> entity and as '\r' char? Can you clarify this point: how actually save
> CR character correctly?
>
> Thank you,
> Alexey
Re: The carriage-return (#xD) character saved as "
\r" [message #427939 is a reply to message #427933] Fri, 06 March 2009 06:59 Go to previous messageGo to next message
Eclipse UserFriend
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...


Tom Schindl wrote:
> Hi,
>
> Well the reason that \r is saved as an escape sequence is that when
> reading XML-Spec it states that \r\n is normalized to \n when parsing
> XML. So when reading back the file using an standard compilant
> XML-Parser the resulting string is:
>
> "Hello\r\n"
>
> because \r\n is normalized to \n. Why the \r is kept when serializing is
> something I can't tell you but at least it should make no difference to you.
>
> Tom
>
> koloale schrieb:
>
>> Hello!
>>
>> When I save resource using Default XML serialization and in that
>> resource some element with value e.g. "Hello\r\nWorld!" is contained, I
>> get XML like that: "Hello
\r\n". I know that 
 is XML entity
>> representin Unicode character for CR, but why it's saved twice as xml
>> entity and as '\r' char? Can you clarify this point: how actually save
>> CR character correctly?
>>
>> Thank you,
>> Alexey
>>
Re: The carriage-return (#xD) character saved as "
\r" [message #427949 is a reply to message #427939] Fri, 06 March 2009 08:23 Go to previous messageGo to next message
Eclipse UserFriend
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 

Alexey
Re: The carriage-return (#xD) character saved as "
\r" [message #427951 is a reply to message #427949] Fri, 06 March 2009 08:50 Go to previous messageGo to next message
Eclipse UserFriend
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&amp;#xD;\r\nWorld", os.toString());
<br>
<br>
So I think it is XMLResourceImpl that convert \r to &amp;#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--
Re: The carriage-return (#xD) character saved as "&#xD;\r" [message #427960 is a reply to message #427933] Fri, 06 March 2009 13:57 Go to previous message
Eclipse UserFriend
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 "&#xD;\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
Previous Topic:URI Encoding problem
Next Topic:reflection
Goto Forum:
  


Current Time: Wed Jul 02 17:21:21 EDT 2025

Powered by FUDForum. Page generated in 0.03557 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top