Updated with solution.
Initial Problem:
I wanted to parse through an XML file using only a single array:
var my Array:Array = ["a", "b"] //for example
and the unique ‘local’ attribute on certain nodes.
Solution:
A new class:
package com.rragona.utils.coreXML
{
/**
* ...
* @author rragona
* @version 1.0
*
* This class is intended to take a url-style string (i.e. '/news/archive/2751/')
* and path through a given XML object, using node attributes (@local) to
* return a specfic XML object.
*
*/
public class XMLPathfinder
{
public function XMLPathfinder()
{
trace('XMLPathfinder is a static class and should not be instantiated.')
}
public static function loopURL(xml:XML, path:String):XML
{
var mA:Array = retPath(path);
var retXML:XMLList = xml.*;
for (var z:int = 0; z < mA.length; z++)
{
retXML = findMatch(retXML, mA[z])
}
return retXML.parent();
}
private static function findMatch(xml:XMLList, path:String):XMLList
{
var retList:XMLList = new XMLList();
for (var z:int = 0; z < xml.length(); z++)
{
if (xml[z].@local == path)
{
retList = xml[z].*;
break;
}
}
return retList;
}
private static function retPath(path:String):Array
{
var rArray:Array = new Array();
var fP_A:Array = path.split('/');
for (var z:int = 1; z < fP_A.length - 1; z++)
{
rArray.push(fP_A[z]);
}
return rArray;
}
}
}