xmlutility
package {
public class XMLUtilities
{
//
public static function XMLListToSimpleArrayByDepth(xmlList:XMLList, depthLimit:int=10):Array{
var resultArr:Array=new Array();
for each (var i:XML in xmlList){
resultArr =XMLToSimpleArrayByDepth(i,resultArr, depthLimit+1);
}
return(resultArr);
}
private static function XMLToSimpleArrayByDepth(xml:XML, targetArr:Array, depthCur:int=10):Array{
depthCur–;
for each (var i in xml.children()){
if (IsTextNode(i)){
targetArr.push(i);
}else{
if (depthCur<=0){continue}
targetArr=XMLToSimpleArrayByDepth(i,targetArr, depthCur);
}
}
return(targetArr);
}
//
public static function XMLListToSimpleArray(xmlList:XMLList):Array{
var resultArr:Array=new Array();
var textXMLList:XMLList=xmlList..*.(children().length()===0);
for each (var i:XML in textXMLList){
resultArr.push(i);
}
return(resultArr);
}
//
public static function XMLToSimpleArray(xml:XML):Array{
var resultArr:Array=new Array();
var textXMLList:XMLList=xml..*.(children().length()===0);
for each (var i:XML in textXMLList){
resultArr.push(i);
}
return(resultArr);
}
//
public static function XMLListToComplexArray(xmllist:XMLList):Array{
var resultArr:Array=new Array();
for each (var i:XML in xmllist){
if(IsTextNode(i)){
resultArr.push(i);
}else{
resultArr.push(XMLToComplexArray(i));
}
}
return(resultArr);
}
//
public static function XMLToComplexArray(xml:XML):Array{
var resultArr:Array=new Array();
for each (var i:XML in xml.children()){
if(IsTextNode(i)){
resultArr.push(i);
}else{
resultArr.push(XMLToComplexArray(i));
}
}
return(resultArr);
}
//Text or not
public static function IsTextNode(xml:XML):Boolean{
return((xml.children().length()==0)? true:false);
}
//
public static function HasNode(xml:XML,name:String):int{
return(xml[name].length());
}
//
public static function HasAttribute(xml:XML,attName:String):int{
return(xml.@[attName].length());
}
}
}