I don't think you need to know the depth of the node in order to
create a chart because you can traverse the XML and generate the chart
as you go along.

But if you need to know the deapth:

function transformXMLWithParentCount(original:XML, xml:XML, n:uint):void {
                for(var i:uint = 0, len:uint = xml.children().length(); i < 
len; i++){
                        original..*.(@name == xml.children()[...@name && @title 
==
xml.children()[...@title)....@parent = n;
                        transformXMLWithParentCount(original, 
xml.children()[i], n + 1);
                }
}

var testXML:XML = <person name="Ted" title="director of the world">
                                                                <person 
name="Bob" title="deputy director of the world">
                                                                <person 
name="Jim" title="Manager - North America">
                                                                <person 
name="Sampson" title="Lead - Western States"/>
                                                                <person 
name="Sophia" title="Lead - Eastern States"/>
                                                                </person>
                                                                <person 
name="Sally" title="Manager - South America"/>
                                                                <person 
name="Sarah" title="Manager - Africa"/>
                                                                </person>
                                                        </person>;
                                        
transformXMLWithParentCount(testXML, testXML, 1);
trace(testXML);

Trace:
<person name="Ted" title="director of the world">
  <person name="Bob" title="deputy director of the world" parent="1">
    <person name="Jim" title="Manager - North America" parent="2">
      <person name="Sampson" title="Lead - Western States" parent="3"/>
      <person name="Sophia" title="Lead - Eastern States" parent="3"/>
    </person>
    <person name="Sally" title="Manager - South America" parent="2"/>
    <person name="Sarah" title="Manager - Africa" parent="2"/>
  </person>
</person>

But this fails when you have two or more people with identical name
and title: you should create unique ID for each person :)
-- 
Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 22 March 2010 17:33, Lehr, Theodore <ted_l...@federal.dell.com> wrote:
> Perhaps I do have a bigger issue (actually, I have LOTS of issues ;-), but 
> the reason I need to know the depth is my thought was to use that as a means 
> of assisting in layout.... for example, say you have the follwing xml:
>
> <person name="Ted" title="director of the world">
>     <person name="Bob" title="deputy director of the world">
>           <person name="Jim" title="Manager - North America">
>                  <person name="Sampson" title="Lead - Western States"/>
>                  <person name="Sophia" title="Lead - Eastern States"/>
>           </person>
>           <person name="Sally" title="Manager - South America"/>
>           <person name="Sarah" title="Manager - Africa"/>
>    </person>
> </person>
>
> And you used this to create an organizational flow chart... my thought was to 
> use the depth to figure out where the names should go... I have thought about 
> how to do this 12,002 ways so my head is getting muddled....
>
> ________________________________________
> From: flashcoders-boun...@chattyfig.figleaf.com 
> [flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks 
> [flash...@stevensacks.net]
> Sent: Monday, March 22, 2010 1:15 PM
> To: Flash Coders List
> Subject: Re: [Flashcoders] xml: counting parents
>
> I think you mean ancestors. A node can only have one parent. Parents can have
> many children.
>
> I think you have a bigger issue, though. Why do you need to know the depth of 
> an
> xml node? I can't think of a single example that I would need that 
> information.
>
>
> On 3/22/2010 9:27 AM, Lehr, Theodore wrote:
>> I am still trying to find a way to see where a child is within the xml - on 
>> what level... is it possible to count a nodes parents?
>>
>> So if I had:
>>
>> <person att="1">
>>        <person att="2">
>>             <person att="3"/>
>>             <person att="4"/>
>>        </person>
>> </person>
>>
>> 1 would return that it has 0 parents, 2 would say it has 1 parent, 3&  4 
>> would say they have 2 parents....
>>
>> hope that makes sense....
>>
>> Ted

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to