G
Greg Diffor wrote: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?
luck, db
There are no new questions, but there may be new answers.
G
Greg Diffor wrote: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.
G
Greg Diffor wrote: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.
Steve
G
Paul Clapham wrote:If you want a new line character in an XML text node you can just put a new line character there.
SCJP 1.5(97%) My Blog
Greg Diffor wrote: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.
Greg Diffor wrote: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.
shivendra tripathi wrote:
Paul Clapham wrote:If you want a new line character in an XML text node you can just put a new line character there.
I didn't get it. I think thats what the problem is having \n in xml and that is getting modified to \\n.
luck, db
There are no new questions, but there may be new answers.
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|