views:

592

answers:

3

I'm importing text in from an xml file and i'm using htmlText to try to keep some styling with tags. I have both the regular and bold face font embedded, and the bolding works fine. The problem is that it ads spaces around the words in bold like a paragraph indent and then makes a line-break after them. What's going on, is there a way to fix?

fromxmlText.htmlText = theXML.contenttext;

If I pull the text in from a txt file it will work fine, but taking it out of an xml file causing funky formatting. lil' help?

A: 

It's hard to say without seeing your XML, but try fiddling with the global XML properties especially ignoreWhitespace. Depending on your line endings, you may also need to strip them before putting the text into the textfield.

grapefrukt
A: 

if you are embedding from xml then make sure that you are using CDATA tags to show preformatted code, otherwise you are outputting the content of multiple nodes in XML.

see w3 schools for more info.

shortstick
+1  A: 

To add HTML into XML you must use CDATA blocks otherwise the HTML is considered part of the XML document.

e.g.

<root>
    <someHtml><![CDATA[I can contain<br />html tags]]></someHtml>
    <somePlainText>I cannot contain html tags since they will be 
                   seen as XML nodes</somePlainText>
</root>

Also make sure you are saving your XML files with unix line endings and encoded as utf-8. If you are using windows line endings (\r\n) then Flash tends to double space newlines. Your editor should allow you to specify the line endings.

James Fassett
+1. But just to be safe, it's a good idea to replace `\r\n` with `\n` in the code (in case someone else edits the xml and forgets to change line endings).
Juan Pablo Califano
I wasn't using the \n or \r. just the <b> tags. This suggestion totally fixes my issue. I figured that it was being read as nodes, but I didn't know how to fix it. Thanks!
HeroicNate
@HeroicNate. Ok. But if someone edits the XML, it's possible that they break text into lines if it's too long (even though they put a <br> as well). Depending on your editor configuration, that will be translated to a newline or a carriage return + newline. I've seen that happen, that's why I suggested the extra check.
Juan Pablo Califano