XML Pre Processing for handling XML

When we want to handle external Html files as XML, say for example using my transformTags() code, we face the problem of unclosed tags like <br> tag. To fix this problem we can overwrite onData method of XML object as shown below. It basically replaces all <br> tags with <br/> before parsing the XML data

[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]
 ************************************************************
 */
//fix the BR tags by closing
XML.prototype.onData = function(txt) {
   txt = txt.split("
").join("
");
   txt = txt.split("
").join("
");
	this.parseXML(txt);
};
/*
//sample code
my_xml = new XML();
my_xml.load("BrFix.xml")
//BrFix.xml contains "my name is
 arul"
trace(my_xml.status);
//traces 0
trace (my_xml.toString());
//traces "my name is
 arul"
*/

Leave a Reply