
Added by roScripts on August-25-2007, 2:45 pm
/*
************************************************************
Developed by R.Arul Kumaran [arul@shockwave-india.com] *
for more code keep visiting [www.shockwave-india.com/blog] *
************************************************************
*/
/*
| XMLNode.transformTags(formatObject,AllowTagsByDefault) - Remove,Process any Tag in an XML file
| formatObject - a generic Object which contains the info on how to modify the tags.
| AllowTagsByDefault - boolean value which specifies whether to allow unspecified tags or not
*/
XMLNode.prototype.transformTags = function(formatObj, AllowTags, depth) {
var str = "";
if (this.nodeType == 1) {
var tag = {start:"", end:""};
var attribObj = {};
var aList = "";
var depth = depth == undefined ? 0 : depth+1;
var c = this.childNodes;
for (var i = 0; i<c.length; i++) {
if (c[i].nodeType == 1) {
var buildTag = false;
var name = c[i].nodeName.toLowerCase();
var obj = formatObj[name];
if (obj != undefined) {
if (typeof (obj) == "boolean") {
buildTag = obj;
} else if (typeof (obj) == "string") {
name = obj;
buildTag = true;
} else if (obj instanceof Function) {
tag = obj(c[i]);
} else if (obj instanceof Object) {
if (obj.__replace__ != undefined) {
name = obj.__replace__ instanceof Function ? obj.__replace__(name) : obj.__replace__;
}
for (a in c[i].attributes) {
var val = c[i].attributes[a];
var aObj = obj[a];
if (aObj != undefined) {
if (typeof (aObj) == "string") {
a = aObj;
} else if (aObj instanceof Object) {
if (aObj.__replace__ != undefined) {
a = aObj.__replace__ instanceof Function ? aObj.__replace__(a) : aObj.__replace__;
}
if (aObj.__value__ != undefined) {
val = aObj.__value__ instanceof Function ? aObj.__value__(val) : aObj.__value__;
}
}
}
attribObj[a] += val;
}
buildTag = true;
}
}else if (AllowTags) {
var attribObj = c[i].attributes;
buildTag = true;
}
for (attrib in attribObj) {
aList += " "+attrib.toLowerCase()+"=\""+attribObj[attrib]+"\"";
}
if (buildTag) {
tag.start = "<"+name+aList+">";
tag.end = "</"+name+">";
}
str += tag.start+c[i].transformTags(formatObj, AllowTags, depth)+tag.end;
} else {
str += c[i].nodeValue;
}
}
} else {
return this.nodeValue;
}
return str;
};
ASSetPropFlags(XMLNode.prototype, ["transformTags"], 1);
/*
Example:-
#include "XMLNode-transformTags.as"
//create an object to specify the format
var fObj = {};
//remove all <i> tags
fObj.i = false;
//change all <b> tags to <strong>
fObj.b = "strong";
//create XML
my_xml = my_xml=new XML("My <i>name</i> <u>is</u> <b>Arul</b>");
//apply the transform with allow tags
trace(my_xml.transformTags(fObj, true));
//traces 'My name <u>is</u> <strong>Arul</strong>'
//
//apply the transform with out allow tags
trace(my_xml.transformTags(fObj));
//traces 'My name is <strong>Arul</strong>'
//
// for more examples visit my blog :)
*/
Added by roScripts on March-26-2008, 5:14 pm
Added by roScripts on March-26-2008, 5:13 pm
Added by roScripts on March-26-2008, 5:09 pm
Added by roScripts on March-26-2008, 5:08 pm
Added by roScripts on March-26-2008, 5:07 pm