1

I want to write a simple message with a line break in the middle. I know that in Java you can do something like the following:

"Hey, this is a message" + \n + "...and this is the rest of it on a new line"

How can I do the same in XML? Can I use the \n escape character or do I use the html line break?

I would like to add a message to the following element in the ObjectValue attribute:

<EnterValue ScreenName="" ObjectName="EMAIL_MESSAGE" ObjectValue=""/>
2
  • possible duplicate of Line Break in XML? Commented Aug 9, 2013 at 16:15
  • @DarkCthulhu: not precisely a duplicate - the cited question aims at inserting content of xml elements into html, the latter requiring a markup representation of a newline. Commented Aug 9, 2013 at 16:21

1 Answer 1

2

use the numrical entity representation of xml: &#x<hex code of char>;, eg &#x0a;,&#x0d; for a LF, CR, respectively.

note that this method works without regard to the character set and/or encoding being used as the byte range 0x00 - 0x7f is shared by all encodings (roughly speaking at least. ebcdic will be different. but the dichotomy between unicode encodings vs. byte-oriented charsets will be covered).

Sign up to request clarification or add additional context in comments.

6 Comments

I tried doing something like this "Message 1 &#x0d; Message 2" but it is still on the same line. How should it be formatted?
try &#x0a;, &#x0d;&#x0a; at first. which application will display your xml data?
It's being displayed in IE9.
So, by copying exactly what you had, I got "Message 1 [new line] , [new line] Message 2
Alright, I got the desired results with just &#x0d;&#x0a;. Thanks! This seems kind of like a hack or workaround. Is there another way?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.