Flash AS3 和 XML:修复使用 的 htmlText 中的换行符的方法xml 中的标签?
我正在从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
要将 HTML 添加到 XML 中,您必须使用 CDATA 块,否则 HTML 被视为 XML 文档的一部分。
例如,
还要确保您保存的 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.
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.我正在将动态 rss feed 导入到嵌入了 html 标签的 Flash 广告中。我也遇到了同样的问题。我使用正则表达式来查找和替换。这是我正在使用的功能。你可以使用我的正则表达式代码来做同样的事情。看来我们遇到了同样的问题。希望这有帮助:
function Parserover_feature(rover_feature:XML):void {
}
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 {
}
如果没有看到您的 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.
如果您从 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.
在使用
ie 设置 textField.htmlText = xml 之前,还要确保您的 textField 设置为
multiline
希望这会有所帮助。
Also make sure your textField is set to
multiline
before you set your textField.htmlText = xml withi.e.
Hope this helps.