PDA

View Full Version : \n not working from XML!??!


punjab4833
01-21-2004, 12:20 PM
I'm pulling in text from an XML file which is being loaded into the variable of a Dynamic Text field. For some reason it will not evaluate any \n as a new line. I just replaced the code with "test\nthis\nout\nnow" instead of the variable I've gotten the XML data from, and it correctly displays each word on a new line.

Does anyone know how to get \n's to correctly evaluate to a new line when pulling them in from an XML file??!?!

punjab4833
01-21-2004, 02:46 PM
In case anyone was wondering about this, here's how I fixed the problem:

When the text is pulled in from the xml file, it seems like a "\n" is put in properly, but when displayed in the textfield, it doens't automatically interpret it as a new line.

So to fix it, I did the following (assuming the variable 'bodyText' has the text pulled into it from the XML file) :

*****
txt = bodyText.split("\\n");
bodyText = "";
for(i = 0; i < btxt.length; i++) {
bodyText += btxt[i] + "\n";
}

*****

you have to split the variable of all \n instances, but in the split, you must escape the backslash, so split("\\n") does the trick!