views:

63

answers:

2

(I'm doing this in AS3, but I'm sure the answer could be given in psuedocode)

Basically, I have a XML file similar to:

<Main>
 <Event>
  <Name>Blah</Name>
  <Event>
   <Name>Blah2</Name>
   <Event>
    <Name>Blah3</Name>
    ...
   </Event>
  </Event>
 </Event>
</Main>

Yeah, to some extent it's poor design. But the idea I'm going for is that any Event has the potential to compromise of other Events and this idea kinda loops.

Any ideas on how to do this?

+2  A: 

Use recursion ?

Alex Reitbort
I get that part, but how...? Like a recursive function?
Firstmate
A: 

var xml:XML = < Main >

            <Event>
              <Name>Name1<Name>
              <Event>
                 <Name>Name2</Name>
                 ...........
              </Event>
            </Event>

          </Main>

var event:MyEvent = getEvent(xml);

function getEvent(xml:XML):MyEvent {

var event:MyEvent = new MyEvent();
 var xmlList:XMLList = xml.children();
 for(i = 0; i < xmlList.length(); i++){
 if(xml[i].hasOwnProperty("Name")){
   event.name = xml[i]["Name"];
  }
 if(xml[i].hasOwnProperty("Event")){
   event.event = getEventVO(xml[i]["Event"]);
  }

 }
return event;

}

MyEvent.as

package {

public class MyEvent {

 public var name:String;
 public var event:Event;

 public function MyEvent():void
 {
 }

}

}

particle