Flash AS3 和 XML:修复使用 的 htmlText 中的换行符的方法xml 中的标签?

发布于 2024-09-05 05:32:14 字数 254 浏览 9 评论 0原文

我正在从 xml 文件导入文本,并使用 htmlText 尝试保留一些带有标签的样式。我嵌入了常规字体和粗体字体,并且粗体效果很好。问题在于,它会像段落缩进一样在粗体单词周围添加空格,然后在它们后面进行换行。这是怎么回事,有办法解决吗?

fromxmlText.htmlText = theXML.contenttext;

如果我从 txt 文件中提取文本,它会正常工作,但从 xml 文件中提取文本会导致奇怪的格式。小帮助?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我家小可爱 2024-09-12 05:32:14

要将 HTML 添加到 XML 中,您必须使用 CDATA 块,否则 HTML 被视为 XML 文档的一部分。

例如,

<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>

还要确保您保存的 XML 文件具有 unix 行结尾并编码为 utf-8。如果您使用 Windows 行结尾 (\r\n),则 Flash 倾向于使用双倍空格换行符。您的编辑器应该允许您指定行结尾。

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.

公布 2024-09-12 05:32:14

我正在将动态 rss feed 导入到嵌入了 html 标签的 Flash 广告中。我也遇到了同样的问题。我使用正则表达式来查找和替换。这是我正在使用的功能。你可以使用我的正则表达式代码来做同样的事情。看来我们遇到了同样的问题。希望这有帮助:

function Parserover_feature(rover_feature:XML):void {

var s:String = rover_feature.items.item[0].article;
s = s.replace(/(?:<br>)+/gi, '<br>');
s = s.replace(/\n/g, '');
container.info_txt.htmlText = s
//trace (s);

}

I was importing a dynamic rss feed into a flash ad of mine that had html tags embedded. I was having the same problem. I used regex to find and replace. Here is the function I was using. you can prob use my regex code in there to do the same thing. It seems like we were having the same problem. Hope this helps:

function Parserover_feature(rover_feature:XML):void {

var s:String = rover_feature.items.item[0].article;
s = s.replace(/(?:<br>)+/gi, '<br>');
s = s.replace(/\n/g, '');
container.info_txt.htmlText = s
//trace (s);

}

古镇旧梦 2024-09-12 05:32:14

如果没有看到您的 XML,很难说,但请尝试摆弄 全局 XML 属性< /a> 特别是ignoreWhitespace。根据您的行结尾,您可能还需要在将文本放入文本字​​段之前删除它们。

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.

久光 2024-09-12 05:32:14

如果您从 xml 嵌入,请确保您使用 CDATA 标签来显示预先格式化的代码,否则您将输出 XML 中多个节点的内容。

有关详细信息,请参阅 w3 学校

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.

呆° 2024-09-12 05:32:14

在使用
ie 设置 textField.htmlText = xml 之前,还要确保您的 textField 设置为 multiline 希望

var myText:TextField = new TextField();
myText.multiline = true;
myText.htmlText = (your xml node with the <br/ >);
addChild(myText);

这会有所帮助。

Also make sure your textField is set to multiline before you set your textField.htmlText = xml with
i.e.

var myText:TextField = new TextField();
myText.multiline = true;
myText.htmlText = (your xml node with the <br/ >);
addChild(myText);

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文