Greg Diffor

Greenhorn
+ Follow
since Mar 20, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Greg Diffor

You're all full of great advice. I'm learning a lot here.

If I use a CDATA construct, will I also get all the other whitespace caused by indenting? I know it's a minor issue because I could just not indent it, but I may not be the only one maintaining this xml file.

14 years ago
Don't know if that's true. The reason I had it in there in the first place is because I originally just had text in my xml formatted the way I'd like to see it in the email (with paragraphs separated by blank lines). When the email came out, the "new line" characters were treated like plain white space and everything was on one line.

So I put \n's in there to try to force new lines where I wanted them.
14 years ago
That makes sense. When I read the xml and place it in a String object, then my "\" is escaped to make sure that it is handled as a single backslash.

I ended up using a unique character sequence of my own device to represent a new line. Then when the xml is parsed and the String is created, I do a



This results in a String object containing "stuff...\n...stuff"

I'm good now, but thanks for the clarification.
14 years ago
I have an input string being read from an xml file. The string has a literal \n in it so that when it is written (in an email in this case) it will force a new line.

When I read the xml file (using apache's xerces), and assign the input to a String, the resulting String contains \\n (i.e. it is being escaped for me).

Here's the actual line of code:



So if my xml contains <content>blah blah blah\nblah blah blah</content>, the assignment to my String object is "blah blah blah\\nblah blah blah.

Because the \ is being escaped, the resulting email gets "un-escaped" and shows \n in it instead of recognizing the \n as an escape for "new line"

How do I keep an assignment into a String object from escaping the backslash or do I need to un-escape it manually using a REGEX?

14 years ago