How to read multiple lines text from a xml file in Action Script?
An initial try would be to add n between the text where we want new lines to be created. See below
<?xml version="1.0" encoding="utf-8"?> <MultiLineText><![CDATA[This is first line\n This is second line\n This is third line]]> </MultiLineText>
Oops! But this doesnt work! n would appear as it is with all text appearing in a single line in Flash!!
Well, the solution is not to add n, but to enter the text in CDATA itself in multiple lines. See below now.
<?xml version="1.0" encoding="utf-8"?> <MultiLineText><![CDATA[This is first line This is second line This is third line]]> </MultiLineText>
Great! The above change would work, except that if the xml file is saved in windows text format ie CRLF used as newline character, then you would end up having an extra empty line between each line as follows:
This is first line This is second line This is third line
This is because flash treats CRLF as two enter keys and hence adds two n at the end of each line in your xml file.
So what is the solution? Well simply save your xml file in Unix format ie only LF used as newline character not CRLF. And how to do that? Well you can use my most favorite Freeware text editor ConTEXT
Once you save the xml file with only LF used as newline separator, AS3 would read your multi line text as







Open your document in ConTEXT and go to
Tools -> Convert Text To -> UNIX (LF Only)
This will convert all CRLF in the document to LF character.
Hi,
i installed “most favorite Freeware text editor ConTEXT”.
But tell me how to convert CRLF xml document to LF document.
I am having the issue you explained here. My xml file is being created by C# Code.
Thanks
Imran