Represent XML as a HTML in Flex RichEditableText

138 views Asked by At

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?

0

There are 0 answers