XMLNE

/*
 * XMLNE 
 *
 * @author: showjean in http://showjean.com/works
 * @version: 1.0.0
 * @date: 2008.7.11.
 *
 * @comment: XML의 각 노드의 속성과 노드밸류를 Object형태로 반환
 
 var xml:XML = new XML('
 
	
		
			showjean
		
		
			qwer
		
		
			1111
		
	

');
 
 
 var obj:Object = XMLNE.create(xml.firstChild);
 
 obj.attributes.text -> "abcd"
 obj.test[0].attributes.name -> "dododo"
 obj.test[0].unit[0].value -> "showjean"
 obj.test[0].unit[0].attributes.type -> "string"
 
 * 
 */
class com.showjean.XMLNE { 

	public static function create(xml:XMLNode):Object {
		var x:XMLNE = new XMLNE();
		return x.adapt(xml);
	}
	private function adapt(xml:XMLNode):Object {
		var obj:Object = new Object();

		// 속성 저장/
		for (var name in xml.attributes) {
			obj.attributes = xml.attributes;
			break;
		}
		for (var currentNode:XMLNode = xml.firstChild; currentNode != null; currentNode=currentNode.nextSibling) {
			var name:String = currentNode.nodeName;
			if (currentNode.nodeType == 1) {
				if (obj[name] == undefined) {
					obj[name] = new Array();
				}
				obj[name].push(arguments.callee(currentNode));
			} else if (currentNode.nodeType == 3) {
				obj["value"] = currentNode.nodeValue;
			}
		}
		return obj;
	}
}

'Flash > AS2.0' 카테고리의 다른 글

crossdomain //2007/03/18 14:44  (0) 2012.06.05
Event  (0) 2012.06.05
XMLLoaderNE  (0) 2012.06.05
Adapter  (0) 2012.06.05
SimpleButtonHandler //2007/03/18 13:22  (0) 2012.06.05