Reputation: 442
I want to convert one XML type value to String type value and for that I am using toString() method to achieve that but problem is that on converting from XML to String I am getting some "\n"(Break statement) in that string variable.
But I don't know why that is coming, I am currently using the following codes for conversion:
My XML is:
var text:XML = new XML(<HTML>
<BODY>
<P ALIGN="left">
<FONT>
<FONT SIZE="32">
Some Text Here
</FONT>
</FONT>
</P>
</BODY>
</HTML>);
Following code I am using for converting XML to String:
var textString:String = (text.normalize()).toString();
But if I am checking the variable textSring then I am getting the following result:
<HTML>\n <BODY>\n <P ALIGN="left">\n <FONT>\n <FONT SIZE="32">Some Text Here</FONT>\n </FONT>\n </P>\n </BODY>\n</HTML>
But I don't know why "\n" is coming after converting to String.
If anybody can find where I am doing wrong so that I am getting the result like this and how to resolve this problem please help me to solve.
Upvotes: 0
Views: 263
Reputation: 15881
\n
means new line. This happens when enter
key is pressed (eg: while making your XML text).
Did you directly copy/paste the XML text from another program? I would not expect Flash IDE to think your enter
presses must become \n
in text. An external program might pass such "new line" instructions along with the copied text as part of display instructions.
Option #1 : Try without normalize
function (is it better?).
var textString:String = text.toString();
Option #2 : Try to keep same multi-line formatting.
var textString:String = (text.normalize()).toString();
textString = textString.replace("\\n", "\n");
Option #3 : Just clean the string by removing all the \n
chars (loses multi-line fomatting).
var textString:String = (text.normalize()).toString();
textString = textString.replace("\n", "");
trace ("textString is : " + "\n" + textString);
Upvotes: 2
Reputation: 768
this solves the problem
var textString:String = (text.normalize()).toString().split("\n").join("");
Upvotes: 2