DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Actionscript _XML Class

02.13.2007
| 5254 views |
  • submit to reddit
        
import _String;

dynamic class _XML extends XML {
	function _XML() {
		
	}
	
	public function $N(tag,xmlNode,xmlNodeArray){
		if (xmlNode == undefined) var xmlNode = this;
		if (xmlNodeArray == undefined) var xmlNodeArray:Array = new Array();
		var nodeArray:Array = new Array();
		
		for (var x=0; x<xmlNode.childNodes.length; x++) {
			if (xmlNode.childNodes[x].nodeType == 1){
				if (xmlNode.childNodes[x].nodeName == tag) xmlNodeArray.push(xmlNode.childNodes[x]);
				$N(tag,xmlNode.childNodes[x],xmlNodeArray);
			}
		}
		return xmlNodeArray;
	}
	
	// If multiple, returns a nodeValue Array
	// If single, returns a nodeValue String
	public function $V(tag,xmlNode) {
		if (xmlNode == undefined) var xmlNode = this;
		var n = $N(tag,xmlNode);
		if (n.length == 1){
			var nV = n[0].firstChild.nodeValue;
			if (nV != undefined){
				nV = escape(nV);
				nV = _String.Replace(nV,"%C2%93","%22");
				nV = _String.Replace(nV,"%C2%94","%22");
				nV = unescape(nV);
			}
			return nV;
		}
		else {
			var vArray:Array = new Array();
			for (var i:String in n) {
				vArray[i] = n[i].firstChild.nodeValue;
				if (vArray[i] != undefined){
					vArray[i] = escape(vArray[i]);
					vArray[i] = _String.Replace(vArray[i],"%C2%93","%22");
					vArray[i] = _String.Replace(vArray[i],"%C2%94","%22");
					vArray[i] = unescape(vArray[i]);
				}
			}
			return vArray;
		}
	}
}