Re: [Flashcoders] xml: counting parents

2010-03-23 Thread Kerry Thompson
Dave Watts wrote:

 So if there's an organizational shuffle of roles, I'd have to rewrite
 my XML schema? Because that sort of thing happens all the time, and a
 rigid hierarchy simply won't be able to match that without frequent
 changes.

I thought of that, which is why I suggested using something like
level1, level2, and putting the actual title as a parameter. There are
drawbacks to that approach, of course, as you and Steven pointed out.

The thing that's missing, so far, is the structure--who reports to
whom, whether it's a direct report or dotted-line, what the hierarchy
is. You have to have that information to have a usable org chart.

Steven is right--you shouldn't have to change your classes when your
organization changes. The only way I see to do that is to include
hierarchical information in the XML, and let your code handle the
display.

Cordially,

Kerry Thompson
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] xml: counting parents

2010-03-23 Thread Dave Watts
 The thing that's missing, so far, is the structure--who reports to
 whom, whether it's a direct report or dotted-line, what the hierarchy
 is. You have to have that information to have a usable org chart.

The hierarchy of the XML document itself can provide that information.
The only issue I can think of offhand is how you'd handle matrix
management, but even that could be modeled strictly by hierarchy,
using either duplicate elements or an attribute that lets one element
point to another.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] xml: counting parents

2010-03-23 Thread Gregory Boudreaux
In our organization, I can find any employee ID and their Manager's ID.
Do you have that information available?  I once built an AJAX app that
functioned as a tree view of an organization by knowing who an
employee's manager is.

gregb



-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Dave
Watts
Sent: Tuesday, March 23, 2010 9:05 AM
To: Flash Coders List
Subject: Re: [Flashcoders] xml: counting parents

 The thing that's missing, so far, is the structure--who reports to
 whom, whether it's a direct report or dotted-line, what the hierarchy
 is. You have to have that information to have a usable org chart.

The hierarchy of the XML document itself can provide that information.
The only issue I can think of offhand is how you'd handle matrix
management, but even that could be modeled strictly by hierarchy,
using either duplicate elements or an attribute that lets one element
point to another.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

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


Re: [Flashcoders] xml: counting parents

2010-03-23 Thread kennethkawam...@gmail.com
I am not a database person but I think in this case you would have 2
tables in the database: one for roles/report lines and one for
employees - they are two completely different data sets. (And the 3rd
table for the relationships between the two.)
-- 
Kenneth Kawamoto
http://www.materiaprima.co.uk/
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] xml: counting parents

2010-03-23 Thread Karl DeSaulniers
Actually you can have a field in the employees dataset that lists the  
manager overseeing

and when you query your employee you can pull that field
and you can also use a wild card to find all employees under that  
manager.


Best,

Karl



On Mar 23, 2010, at 9:17 AM, kennethkawam...@gmail.com wrote:

I am not a database person but I think in this case you would have 2
tables in the database: one for roles/report lines and one for
employees - they are two completely different data sets. (And the 3rd
table for the relationships between the two.)
--
Kenneth Kawamoto
http://www.materiaprima.co.uk/
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Karl DeSaulniers
Design Drumm
http://designdrumm.com

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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Glen Pike

You can access the parent of any XMLNode with it's parentNode property

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


  


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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Henrik Andersson

Glen Pike wrote:

You can access the parent of any XMLNode with it's parentNode property


But that is the old xml parser. Most people uses the new one.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Steven Sacks
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


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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread mark . jonkman
If you have a node, you can count its depth using one of two methods 
calling a recursive function or simply doing something like this: 

var p:XML = myNode; 
var depth:uint = 0; 
while (p.parent() != undefined) 
{ 
depth++; 
p = p.parent(); 
} 

// depth here would be the number of parent. 

if you only want to count parents where parent().name() == person then change 
the while statement to read: 
while ((p.parent() != undefined)  (p.parent().name() == person)) 
{ 
depth++; 
p = p.parent(); 
} 

- Original Message - 
From: Theodore Lehr ted_l...@federal.dell.com 
To: Flash Coders List flashcoders@chattyfig.figleaf.com 
Sent: Monday, March 22, 2010 12:27:50 PM GMT -05:00 US/Canada Eastern 
Subject: [Flashcoders] xml: counting parents 

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 
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread kennethkawam...@gmail.com
It's very hackish, but here we go :)

Say you have this recursive function:

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

You have this XML:

var testXML:XML = root
 person att=1
 person att=2
person att=3/
person att=4/
 /person
 /person
 person att=5
 person att=6
person att=7/
person att=8/
 /person
 /person
   /root;

Then:

transformXMLWithParentCount(testXML, testXML, 0);
trace(testXML);

You should get:

root
  person att=1 parent=0
person att=2 parent=1
  person att=3 parent=2/
  person att=4 parent=2/
/person
  /person
  person att=5 parent=0
person att=6 parent=1
  person att=7 parent=2/
  person att=8 parent=2/
/person
  /person
/root

-- 
Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 22 March 2010 16:27, Lehr, Theodore ted_l...@federal.dell.com 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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Steven Sacks

A few optimizations for general coding practice:

uint is slower than int for math and should only be used if you're not doing 
math on it. Number is faster than uint for numbers higher than int's positive 
limit.  Generally speaking, always use int in for/while loops.


There's no need to call p.parent() twice each loop.  You can shortcut this by 
setting p to its parent in the condition check.


Pre-increment is faster than post-increment.

Searching for a Boolean resolve instead of a specific value is faster.


var p:XML = myNode;
var depth:int;
while (p = p.parent())
{
++depth;
}



On 3/22/2010 10:26 AM, mark.jonk...@comcast.net wrote:

If you have a node, you can count its depth using one of two methods
calling a recursive function or simply doing something like this:

var p:XML = myNode;
var depth:uint = 0;
while (p.parent() != undefined)
{
depth++;
p = p.parent();
}

// depth here would be the number of parent.

if you only want to count parents where parent().name() == person then change 
the while statement to read:
while ((p.parent() != undefined)  (p.parent().name() == person))
{
depth++;
p = p.parent();
}

- Original Message -
From: Theodore Lehrted_l...@federal.dell.com
To: Flash Coders Listflashcoders@chattyfig.figleaf.com
Sent: Monday, March 22, 2010 12:27:50 PM GMT -05:00 US/Canada Eastern
Subject: [Flashcoders] xml: counting parents

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
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


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


RE: [Flashcoders] xml: counting parents

2010-03-22 Thread Lehr, Theodore
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

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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Eric E. Dolecki
How about having the nodes be more descriptive?

director name=Ted
deputy name=Bob
...
/deputy
/director

Then use those node names

On Mon, Mar 22, 2010 at 1:33 PM, Lehr, Theodore
ted_l...@federal.dell.comwrote:

 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
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




-- 
http://ericd.net
Interactive design and development
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Steven Sacks

Why not go from the top down instead of the bottom up?


On 3/22/2010 10:33 AM, Lehr, Theodore 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

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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread kennethkawam...@gmail.com
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


RE: [Flashcoders] xml: counting parents

2010-03-22 Thread Lehr, Theodore
I guess... I just can not wrap my head around how to get a useable number to 
assist in layout... Say that I know the first member will be at the top of the 
chart... then the second - is it a sibling? i.e.

person 1/
person 2/

or is it a child?

person 1
 person 2/
/person

then  auhhh I don;t know I need to go for a run or something and clear 
my head


From: flashcoders-boun...@chattyfig.figleaf.com 
[flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks 
[flash...@stevensacks.net]
Sent: Monday, March 22, 2010 2:03 PM
To: Flash Coders List
Subject: Re: [Flashcoders] xml: counting parents

Why not go from the top down instead of the bottom up?


On 3/22/2010 10:33 AM, Lehr, Theodore 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
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] xml: counting parents

2010-03-22 Thread Lehr, Theodore
But that is what I am trying to do as I go along I am going through the xml 
line by line (of course) so as I go line by line, I need a way to find out who 
this node belongs to and where it should be Is it a sibling of a prevoius 
node or a child of a child


From: flashcoders-boun...@chattyfig.figleaf.com 
[flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of 
kennethkawam...@gmail.com [kennethkawam...@gmail.com]
Sent: Monday, March 22, 2010 2:06 PM
To: Flash Coders List
Subject: Re: [Flashcoders] xml: counting parents

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

Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Kerry Thompson
I agree with Eric. Your basic issue is the way you're forming your XML.

First, the way you have it, there is no need to have a hierarchy. This
would work just as well:
people
   person name=Ted title=director of the world /
   person name=Jim title=Manager - North America /
/people

It would be better, though, to make the node names meaningful and
hierarchical. So, something like this:
management
   world
  directors
 director name=Ted title=director of the world /
 deputy name=Bob title=deputy director of the world /
  /directors
   /world
   continent
  country
 managers
   manager name=Canada manager= Jim title=Manager - Canada
 /managers
 leads
lead name=Sampson title=Lead - Western States/
lead name=Sophia title=Lead - Eastern States/
 /lead
  /country
   /continent
/management

You could come up with a better structure than that, I'm sure, but
that's the basic idea.

Cordially,

Kerry Thompson


On Mon, Mar 22, 2010 at 1:59 PM, Eric E. Dolecki edole...@gmail.com wrote:
 How about having the nodes be more descriptive?

 director name=Ted
 deputy name=Bob
 ...
 /deputy
 /director

 Then use those node names

 On Mon, Mar 22, 2010 at 1:33 PM, Lehr, Theodore
 ted_l...@federal.dell.comwrote:

 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
 
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




 --
 http://ericd.net
 Interactive design and development
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Henrik Andersson

Steven Sacks wrote:

A few optimizations for general coding practice:

uint is slower than int for math and should only be used if you're not
doing math on it. Number is faster than uint for numbers higher than
int's positive limit. Generally speaking, always use int in for/while
loops.


I believe that they fixed that long a go. uint and int has the same speed.


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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Steven Sacks
I disagree with using explicit node names.  He's building an org chart of 
people, so the nodes should be person and the title should be an attribute.


people
person title=CEO name=Bill Gates
person title=President name=Steve Ballmer/
person title=Manager - North America name=Joe Schmoe
person title=Manager - Pacific Northwest name=Bob Jones/
/person
/person
/people


You create a Person VO that you pass the node for deserialization:

public class Person
{
public var title:String;
public var name:String;
public var subordinates:Vector.Person;

public function Person(value:XML)
{
deserialize(value);
}
private function deserialize(value:XML):void
{
title = val...@title;
name = val...@name;
subordinates = parseSubordinates(value.person);
}
private function parseSubordinates(value:XMLList):Vector.Person
{
var vector:Vector.Person = new Vector.Person();
var len:int = value.length();
for (var i:int = 0; i  len; ++i)
{
vector.push(new Person(value[i]));
}
return vector;
}
}

And you feed that to your view which traverses the stack:

public class PersonView extends Sprite
{
protected var _data:Person;

public function PersonView()
{
super();
}
public function set data(value:Person):void
{
_data = value;
draw();
}
public function get data():Person
{
return _data;
}
protected function draw():void
{
// draw based on the data
}
}


Pseudo-code but you get the idea.  The PersonView would create other PersonViews 
inside of itself to draw the subordinates, and each view would be responsible 
for doing its own layout in the draw function, taking into account the 
width/height of its children, etc.  Pretty clean overall.


The reason draw() is protected is because you might want to create concrete 
implementations of PersonView.  Perhaps some titles use a specific view and you 
don't want to clutter PersonView with too many if then else statements, so you 
just instantiate a specific ConcretePersonView based on the _data.title and the 
concrete views take care of drawing themselves.


That's how I would build it, at least.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] xml: counting parents

2010-03-22 Thread Lehr, Theodore
nice... is vector do-able in cs3 - because I am egtting an error on that...


From: flashcoders-boun...@chattyfig.figleaf.com 
[flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks 
[flash...@stevensacks.net]
Sent: Monday, March 22, 2010 3:19 PM
To: Flash Coders List
Subject: Re: [Flashcoders] xml: counting parents

I disagree with using explicit node names.  He's building an org chart of
people, so the nodes should be person and the title should be an attribute.

people
 person title=CEO name=Bill Gates
person title=President name=Steve Ballmer/
person title=Manager - North America name=Joe Schmoe
person title=Manager - Pacific Northwest name=Bob Jones/
/person
 /person
/people


You create a Person VO that you pass the node for deserialization:

public class Person
{
 public var title:String;
 public var name:String;
 public var subordinates:Vector.Person;

 public function Person(value:XML)
 {
 deserialize(value);
 }
 private function deserialize(value:XML):void
 {
 title = val...@title;
name = val...@name;
subordinates = parseSubordinates(value.person);
 }
 private function parseSubordinates(value:XMLList):Vector.Person
 {
var vector:Vector.Person = new Vector.Person();
var len:int = value.length();
for (var i:int = 0; i  len; ++i)
{
vector.push(new Person(value[i]));
}
return vector;
 }
}

And you feed that to your view which traverses the stack:

public class PersonView extends Sprite
{
 protected var _data:Person;

 public function PersonView()
 {
 super();
 }
 public function set data(value:Person):void
 {
 _data = value;
 draw();
 }
 public function get data():Person
 {
 return _data;
 }
 protected function draw():void
 {
 // draw based on the data
 }
}


Pseudo-code but you get the idea.  The PersonView would create other PersonViews
inside of itself to draw the subordinates, and each view would be responsible
for doing its own layout in the draw function, taking into account the
width/height of its children, etc.  Pretty clean overall.

The reason draw() is protected is because you might want to create concrete
implementations of PersonView.  Perhaps some titles use a specific view and you
don't want to clutter PersonView with too many if then else statements, so you
just instantiate a specific ConcretePersonView based on the _data.title and the
concrete views take care of drawing themselves.

That's how I would build it, at least.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] xml: counting parents

2010-03-22 Thread Merrill, Jason
 nice... is vector do-able in cs3 - because I am egtting an error on
that...

No - Vector is only Flash player 10.  But with some tweaks, you can use
Array instead.


Jason Merrill 

Bank of  America  Global Learning 
Learning  Performance Solutions

Join the Bank of America Flash Platform Community  and visit our
Instructional Technology Design Blog
(note: these are for Bank of America employees only)






-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Lehr,
Theodore
Sent: Monday, March 22, 2010 3:40 PM
To: Flash Coders List
Subject: RE: [Flashcoders] xml: counting parents

nice... is vector do-able in cs3 - because I am egtting an error on
that...


From: flashcoders-boun...@chattyfig.figleaf.com
[flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks
[flash...@stevensacks.net]
Sent: Monday, March 22, 2010 3:19 PM
To: Flash Coders List
Subject: Re: [Flashcoders] xml: counting parents

I disagree with using explicit node names.  He's building an org chart
of
people, so the nodes should be person and the title should be an
attribute.

people
 person title=CEO name=Bill Gates
person title=President name=Steve Ballmer/
person title=Manager - North America name=Joe Schmoe
person title=Manager - Pacific Northwest name=Bob
Jones/
/person
 /person
/people


You create a Person VO that you pass the node for deserialization:

public class Person
{
 public var title:String;
 public var name:String;
 public var subordinates:Vector.Person;

 public function Person(value:XML)
 {
 deserialize(value);
 }
 private function deserialize(value:XML):void
 {
 title = val...@title;
name = val...@name;
subordinates = parseSubordinates(value.person);
 }
 private function parseSubordinates(value:XMLList):Vector.Person
 {
var vector:Vector.Person = new Vector.Person();
var len:int = value.length();
for (var i:int = 0; i  len; ++i)
{
vector.push(new Person(value[i]));
}
return vector;
 }
}

And you feed that to your view which traverses the stack:

public class PersonView extends Sprite
{
 protected var _data:Person;

 public function PersonView()
 {
 super();
 }
 public function set data(value:Person):void
 {
 _data = value;
 draw();
 }
 public function get data():Person
 {
 return _data;
 }
 protected function draw():void
 {
 // draw based on the data
 }
}


Pseudo-code but you get the idea.  The PersonView would create other
PersonViews
inside of itself to draw the subordinates, and each view would be
responsible
for doing its own layout in the draw function, taking into account the
width/height of its children, etc.  Pretty clean overall.

The reason draw() is protected is because you might want to create
concrete
implementations of PersonView.  Perhaps some titles use a specific view
and you
don't want to clutter PersonView with too many if then else statements,
so you
just instantiate a specific ConcretePersonView based on the _data.title
and the
concrete views take care of drawing themselves.

That's how I would build it, at least.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Steven Sacks

Vector is Flash 10 only. So I don't think it works in CS3.

You can substitute Array if you're targeting Flash Player 9.


On 3/22/2010 12:39 PM, Lehr, Theodore wrote:

nice... is vector do-able in cs3 - because I am egtting an error on that...


From: flashcoders-boun...@chattyfig.figleaf.com 
[flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Steven Sacks 
[flash...@stevensacks.net]
Sent: Monday, March 22, 2010 3:19 PM
To: Flash Coders List
Subject: Re: [Flashcoders] xml: counting parents

I disagree with using explicit node names.  He's building an org chart of
people, so the nodes should be person and the title should be an attribute.

people
  person title=CEO name=Bill Gates
 person title=President name=Steve Ballmer/
 person title=Manager - North America name=Joe Schmoe
 person title=Manager - Pacific Northwest name=Bob Jones/
 /person
  /person
/people


You create a Person VO that you pass the node for deserialization:

public class Person
{
  public var title:String;
  public var name:String;
  public var subordinates:Vector.Person;

  public function Person(value:XML)
  {
  deserialize(value);
  }
  private function deserialize(value:XML):void
  {
  title = val...@title;
 name = val...@name;
 subordinates = parseSubordinates(value.person);
  }
  private function parseSubordinates(value:XMLList):Vector.Person
  {
 var vector:Vector.Person  = new Vector.Person();
 var len:int = value.length();
 for (var i:int = 0; i  len; ++i)
 {
 vector.push(new Person(value[i]));
 }
 return vector;
  }
}

And you feed that to your view which traverses the stack:

public class PersonView extends Sprite
{
  protected var _data:Person;

  public function PersonView()
  {
  super();
  }
  public function set data(value:Person):void
  {
  _data = value;
  draw();
  }
  public function get data():Person
  {
  return _data;
  }
  protected function draw():void
  {
  // draw based on the data
  }
}


Pseudo-code but you get the idea.  The PersonView would create other PersonViews
inside of itself to draw the subordinates, and each view would be responsible
for doing its own layout in the draw function, taking into account the
width/height of its children, etc.  Pretty clean overall.

The reason draw() is protected is because you might want to create concrete
implementations of PersonView.  Perhaps some titles use a specific view and you
don't want to clutter PersonView with too many if then else statements, so you
just instantiate a specific ConcretePersonView based on the _data.title and the
concrete views take care of drawing themselves.

That's how I would build it, at least.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Kerry Thompson
Steven Sacks wrote:

 I disagree with using explicit node names.  He's building an org chart of
 people, so the nodes should be person and the title should be an attribute.

 people
    person title=CEO name=Bill Gates
        person title=President name=Steve Ballmer/
        person title=Manager - North America name=Joe Schmoe
            person title=Manager - Pacific Northwest name=Bob Jones/
        /person
    /person
 /people

It's unusual to find myself disagreeing with Steven Sacks--you're
usually right on money.

But here I do disagree. An org chart shows the organization of a unit,
and the people are secondary. When Steve Ballmer resigns or gets hired
by Google, Microsoft will still have a president.

It's also clearer to read, and easier to program, when every node
isn't named the same. Of course, there should be some
flexibility--instead of guru name=Mark Jonkman you could have
something more generic, such as level1 name=Steven Sacks.

Cordially,

Kerry Thompson

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


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Dave Watts
 But here I do disagree. An org chart shows the organization of a unit,
 and the people are secondary. When Steve Ballmer resigns or gets hired
 by Google, Microsoft will still have a president.

So if there's an organizational shuffle of roles, I'd have to rewrite
my XML schema? Because that sort of thing happens all the time, and a
rigid hierarchy simply won't be able to match that without frequent
changes.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite.
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] xml: counting parents

2010-03-22 Thread Steven Sacks

 So if there's an organizational shuffle of roles, I'd have to rewrite
 my XML schema? Because that sort of thing happens all the time, and a
 rigid hierarchy simply won't be able to match that without frequent
 changes.

Precisely.

My solution uses design patterns, encapsulation and DRY. It makes for very lean 
code and is completely flexible and scalable.


Also, organizations of people are made up of people, not units. If Steve Ballmer 
leaves and somebody else is President, then the name changes, but not the 
role/title.


I don't see how writing tons of custom Actionscript to parse custom nodes in XML 
is a workable solution.  It's not scalable, it's not flexible.  If you add a new 
role at your company, you have to write new code to support the parsing of that 
node name and a new class to handle drawing it, as well.  The Strategy pattern 
(which is present in my example) was made to solve this issue elegantly.


Let's take it out of XML altogether.  Would you write a bunch of classes like 
this?

public class Director
{
public var title:String;
public var name:String;
public var somethingDirectorsAndAboveHave:String;
public var somethingManagersAndAboveHave:String;
}
public class Manager
{
public var title:String;
public var name:String;
public var somethingManagersAndAboveHave:String;
}
public class Person
{
public var title:String;
public var name:String;
}

Or this...

public class Person
{
public var title:String;
public var name:String;
}
public class Manager extends Person
{
public var somethingManagersAndAboveHave:String;
}
public class Director extends Manager
{
public var somethingDirectorsAndAboveHave:String;
}

If that's even necessary, which I'm not sure it is in the data.  It seems like 
the role of the person only defines how they're rendered in the view and 
potentially what events they fire off to the controller (if you're using 
RobotLegs, you can pair with a Mediator).  Leave rendering instructions out of 
the data and put it in the view where it belongs.

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