There is a thread going on in flashcoders mailing list about how to stripp the HTML tags in the string. Here is my version to do the same using XML. It can be used to remove specific tags from the given string.
Even though we can use flash textField for this purpose (setting the .htmlText property and getting .text property) the following method gives more options and flexibility.
[UPDATE] included the ActionScript 3 version as well 🙂 It became lot more simpler with the regular expressions
/*
************************************************************
Developed by R.Arul Kumaran [[email protected]]
for more code keep visiting [www.luracast.com/all/blog]
************************************************************
*/
/*
Coming Soon....
*/
*/
/*
/*
************************************************************
Developed by R.Arul Kumaran [[email protected]]
for more code keep visiting [www.luracast.com/all/blog]
************************************************************
*/
XMLNode.prototype.strippTags = function(tagList,exclude){
if(exclude != true)exclude = false;
if(tagList == undefined)tagList = "";
if(this.nodeType == 1){
var c = this.childNodes;
var str = "";
for(var i=0; i";
endTag="" + c[i].nodeName + ">";
}
str += startTag + c[i].strippTags(tagList,exclude) + endTag;
}else{
str += c[i].nodeValue;
}
}
}else{
return this.nodeValue;
}
return str;
};
//Usage Examples:-
var my_str="hi! my name is arul"
var my_xml=newXML(my_str);
trace(my_xml.strippTags());
//traces 'hi! my name is arul'
trace(my_xml.strippTags("b"));
//traces 'hi! my name is arul'
trace(my_xml.strippTags("b",true));
//traces 'hi! my name is arul'
trace(my_xml.strippTags("font",true));
//traces 'hi! my name is arul'
This is the one which I’m using in my Reference Viewer Application 😉