Skip to main content
Inspiring
November 16, 2007
Question

Extra line breaks in text loaded from XML

  • November 16, 2007
  • 4 replies
  • 1190 views
Hello all,
So I am loading some text from an XML file. It is a couple of lines, and it loads fine. But, the line breaks show up as more than one break. Actually, it seems like Flash sees it as one large line break or something. For example ...

<?xml version="1.0" encoding="utf-8"?>
<myData>
First Line
Second Line
Third Line
</myData>

... would show up as what looks like triple spaced lines. I was messing around with the ignore white space, but in AS3 that is supposed to be off by default I think. Plus I am not sure that even applys to what I am doing. Ideas?

- B
This topic has been closed for replies.

4 replies

Inspiring
November 16, 2007
no problem. Looks like it will be next week for me to really put in a solid start with as3 now. I had a play with the as3 xml a few months back to compare with as2 and it absolutely rocks.. I just can't remember the details now.
Inspiring
November 16, 2007
Was wondering why it wasn't working... I am VERY new to AS3 - like a few days, so I am not sure of the translation. I'll work it though. Thanks a lot.
Inspiring
November 16, 2007
actually that was as2 so you might need to translate it for the XML stuff for as3, can't remember the differences off hand.
Inspiring
November 16, 2007
Its OS dependent. The XML was probably created in a windows editor.

Windows standard is two characters for a line break. Carriage return+LineFeed.
That's not the same as other OSes which use one (either CR or LF).
Flash seems to use either CR or LF to make a line break.
You can filter them like this
if myNode represents one of your myData nodes...
var stringVal = myNode.firstChild.nodeValue; //text node value
stringVal = stringVal.split("\r\n").join("\r");