Quicktip #3: Getting newlines parsed correctly from XML to AS3

Posted by Bart Claessens on November 25, 2008
QuickTips

Today I stumbled upon the following problem while parsing an xml: I tried to parse an attribute of an XML node which contained ‘\n’-characters and tried to put this parsed text into a dynamic text field on the stage.
Guess what, instead of parsing ‘\n’ to a newline, AS3 showed me the ‘\n’ in my text. This is not as I had hoped.

You can fix this very easily by changing the ‘\n’-characters in your XML to:




Original:

<book name="my \n book"></book>

Changed:

<book name="my &#10; book"></book>

You can find other codes to replace characters with on this reference: w3 schools

  • Share/Bookmark

Tags: , , , , ,

3 Comments to Quicktip #3: Getting newlines parsed correctly from XML to AS3

MurtenSaerbi
February 25, 2009

A “br” tag will work aswell.

Bart Claessens
February 25, 2009

Hi Murten, nice to see you here also. :)

A br-tag will work as well, but I wasn’t using the htmlText property of my TextField. For some mysterious reason (I don’t know exactly which one ) I had to use the .text property of the TextField.

Special characters or the CDATA tags aren’t allowed in attribute tags.

Greets
Bart

MurtenSaerbi
February 25, 2009

Aah very true. It seems a pretty mysterious reason that is keeping you from using the htmlText property, though…

Anyway, I’m glad it worked out! “Nerds unite!” Or is someone else already (ab)using that slogan?

Leave a comment

WP_Big_City