Represent XML as a HTML in Flex RichEditableText

I'm developing a word finder of a large text using flex. There I use a RichEditableText to show the whole text and when I find for a word I want to represent all the matching words of that text in a different colour. So I replace all the matching words with html colour changing tags as follows.

var replacedContent:String = txtRichBox.Text.replace(new RegExp(txtSearch.text,"g"), "<font color='#ff0000'>"+txtSearch.text+"</font>");

And then I set it to the RichEditableText as a HTML as follows.

txtRichBox.textFlow = TextConverter.importToFlow(replacedContent, TextConverter.TEXT_FIELD_HTML_FORMAT);

This works supper fine.

Now I have a new requirement. There the original text can be a XML. Then if I set the XML with colour changing html tags to the RichEditableText as a HTML everything crash because it takes XML tags also as HTML tags.

So I tried to replace < and > sings of the XML with &lt and &gt.

//Replace < with &lt
replacedContent:String = txtFileContent.text.replace(new RegExp("<","g"), "&lt");               

//Replace > with &gt
replacedContent = replacedContent.replace(new RegExp(">","g"), "&gt");

Then RichEditableText won't render them back to < and > sings. It shows &lt and &gt as it is.

Can anyone suggest me a solution for this?

链接地址: http://www.djcxy.com/p/15368.html

上一篇: 如何设置Qtextedit背景颜色?

下一篇: 在Flex RichEditableText中将XML表示为HTML