Question

I got this problem, when edit my xml everything on a next line renders two breaklines

<![CDATA[Line one
Line two
Line three
]]>

Renders in flash as

Line One

Line Two

Line Three

Now I researched this before and it had something to do with hidden breakline characters, Im using Flexbuilder and or Aptana to edit the xml, but how do I avoid having two breaklines when I want one.

Was it helpful?

Solution

Flash interprets both \r and \n as new line characters. If your input contains windows line endings (\r\n), then you see a blank line in the output.

To solve your problem, use the following regex to replace two consecutive occurrences of \r and \n with one before you output your data.

var newline:RegExp = /\r\n|\n\r/g;
var input:String = "your XML CDATA input";
var output:String = input.replace(newline, "\n");

Actually it is unlikely that \n\r ever occurs, but since we are already replacing, we can fix these invalid line endings as well.

OTHER TIPS

Perhaps you're inserting the wrong end-of-line characters. Usually your choices are: cr-lf, cr, and lf. The first works well on windows, the second on Mac, the third on most flavors of Unix. Try setting your editor to use lf (\n).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top