# Multi-level XML parsing with filters

**URL:** <https://forum.kirupa.com/t/multi-level-xml-parsing-with-filters/257529>\
**Category:** Uncategorized\
**Created:** [April 15, 2008, 1:54am UTC](https://forum.kirupa.com/t/multi-level-xml-parsing-with-filters/257529 "2008-04-15T01:54:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [April 15, 2008, 1:54am UTC](https://forum.kirupa.com/t/multi-level-xml-parsing-with-filters/257529/1 "2008-04-15T01:54:19Z")

</div>

Updated with solution.

**Initial Problem:**

I wanted to parse through an XML file using only a single array:

```auto
var my Array:Array = ["a", "b"] //for example

```

and the unique ‘local’ attribute on certain nodes.

**Solution** :

A new class:

```auto

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;
        }
        
    }
    
}

```
