convert the output into an list
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Xml.XPath;
using System.Xml.Linq;
namespace SampleProgram1
{
    class Program
    {
        static void Main(string[] args)
        {
            string xml = @"&lt;people&gt; 
&lt;person&gt;&lt;name&gt;kumar&lt;/name&gt;&lt;school&gt;fes&lt;/school&gt;&lt;parent&gt;All&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;manju&lt;/name&gt;&lt;school&gt;fes&lt;/school&gt;&lt;parent&gt;kumar&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;anu&lt;/name&gt;&lt;school&gt;frank&lt;/school&gt;&lt;parent&gt;kumar&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;anitha&lt;/name&gt;&lt;school&gt;jss&lt;/school&gt;&lt;parent&gt;All&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;rohit&lt;/name&gt;&lt;school&gt;frank&lt;/school&gt;&lt;parent&gt;manju&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;anill&lt;/name&gt;&lt;school&gt;vijaya&lt;/school&gt;&lt;parent&gt;manju&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;vani&lt;/name&gt;&lt;school&gt;jss&lt;/school&gt;&lt;parent&gt;kumar&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;soumya&lt;/name&gt;&lt;school&gt;jss&lt;/school&gt;&lt;parent&gt;kumar&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;madhu&lt;/name&gt;&lt;school&gt;jss&lt;/school&gt;&lt;parent&gt;rohit&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;shiva&lt;/name&gt;&lt;school&gt;jss&lt;/school&gt;&lt;parent&gt;rohit&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;vanitha&lt;/name&gt;&lt;school&gt;jss&lt;/school&gt;&lt;parent&gt;anitha&lt;/parent&gt;&lt;/person&gt; 
&lt;person&gt;&lt;name&gt;anu&lt;/name&gt;&lt;school&gt;jss&lt;/school&gt;&lt;parent&gt;anitha&lt;/parent&gt;&lt;/person&gt; 
&lt;/people&gt;";

            XDocument document = XDocument.Parse(xml);

            var people = (from person in document.Descendants("person")
                          select new Person
                          {
                              Name = (string)person.Element("name"),
                              School = (string)person.Element("school"),
                              Parent = (string)person.Element("parent")
                          }).ToList();

            var parents = people.Where(p =&gt; p.Parent == "All");

            Action&lt;Person&gt; findChildren = null;
            findChildren = person =&gt;
            {
                List&lt;Person&gt; children = people.Where(p =&gt; p.Parent == person.Name).ToList();
                person.Children = children;
                foreach (Person p in children)
                    findChildren(p);
            };

            foreach (Person parent in parents)
            {
                findChildren(parent);
            }


            Action&lt;Person, int&gt; showChildren = null;
            showChildren = (person, tabs) =&gt;
            {
                //Console.WriteLine(new string('\t', tabs) + person.Name);

                if (person.Children != null)
                {
                    foreach (Person p in person.Children)
                        showChildren(p, tabs + 1);
                }
            };

            foreach (Person parent in parents)
            {
                showChildren(parent, 0);
            }
           // Console.Read();
        }
    }

    class Person
    {
        public string Name { get; set; }
        public string School { get; set; }
        public string Parent { get; set; }
        public List&lt;Person&gt; Children { get; set; }
    } 

}
</code></pre>

<p>this my program where i <strong>need to  put the  output into a list</strong> an dthen bind the lsit into  gridview</p>

<p>can any one help me out in syntax achiveing this one.
i am using c# 3.5
once  i create an hierachy  then need  to  format the datalike this based on hierarchy</p>

<p>ex: </p>

<pre><code>namespace SilverlightApplication1
{
    public class SampleProjectData
    {
        public static ObservableCollection&lt;Product&gt; GetSampleData()
        {
            DateTime dtS = DateTime.Now;


            ObservableCollection&lt;Product&gt; teams = new ObservableCollection&lt;Product&gt;();
            teams.Add(new Product() { PDName = "Product1", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3),  });


            Project emp = new Project() { PName = "Project1", OverallStartTime = dtS + TimeSpan.FromDays(1), OverallEndTime = dtS + TimeSpan.FromDays(6)  };
            emp.Tasks.Add(new Task() { StartTime = dtS, EndTime = dtS + TimeSpan.FromDays(2), TaskName = "John's Task 3" });
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(3), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "John's Task 2" });
            teams[0].Projects.Add(emp);


            emp = new Project() { PName = "Project2", OverallStartTime = dtS + TimeSpan.FromDays(1.5), OverallEndTime = dtS + TimeSpan.FromDays(5.5) };
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Victor's Task" });
            teams[0].Projects.Add(emp);

            emp = new Project() { PName = "Project3", OverallStartTime = dtS + TimeSpan.FromDays(2), OverallEndTime = dtS + TimeSpan.FromDays(5) };
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Jason's Task 1" });
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(7), EndTime = dtS + TimeSpan.FromDays(9), TaskName = "Jason's Task 2" });
            teams[0].Projects.Add(emp);

            teams.Add(new Product() { PDName = "Product2", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3) });

            emp = new Project() { PName = "Project4", OverallStartTime = dtS + TimeSpan.FromDays(0.5), OverallEndTime = dtS + TimeSpan.FromDays(3.5) };
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1.5), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Vicky's Task" });
            teams[1].Projects.Add(emp);

            emp = new Project() { PName = "Project5", OverallStartTime = dtS + TimeSpan.FromDays(2), OverallEndTime = dtS + TimeSpan.FromDays(6) };
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(2.2), EndTime = dtS + TimeSpan.FromDays(3.8), TaskName = "Oleg's Task 1" });
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(5), EndTime = dtS + TimeSpan.FromDays(6), TaskName = "Oleg's Task 2" });
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(8), EndTime = dtS + TimeSpan.FromDays(9.6), TaskName = "Oleg's Task 3" });
            teams[1].Projects.Add(emp);

            emp = new Project() { PName = "Project6", OverallStartTime = dtS + TimeSpan.FromDays(2.5), OverallEndTime = dtS + TimeSpan.FromDays(4.5) };
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(0.8), EndTime = dtS + TimeSpan.FromDays(2), TaskName = "Kim's Task" });
            teams[1].Projects.Add(emp);


            teams.Add(new Product() { PDName = "Product3", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3) });

            emp = new Project() { PName = "Project7", OverallStartTime = dtS + TimeSpan.FromDays(5), OverallEndTime = dtS + TimeSpan.FromDays(7.5) };
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1.5), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Balaji's Task 1" });
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(5), EndTime = dtS + TimeSpan.FromDays(8), TaskName = "Balaji's Task 2" });
            teams[2].Projects.Add(emp);

            emp = new Project() { PName = "Project8", OverallStartTime = dtS + TimeSpan.FromDays(3), OverallEndTime = dtS + TimeSpan.FromDays(6.3) };
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1.75), EndTime = dtS + TimeSpan.FromDays(2.25), TaskName = "Li's Task" });
            teams[2].Projects.Add(emp);

            emp = new Project() { PName = "Project9", OverallStartTime = dtS + TimeSpan.FromDays(2), OverallEndTime = dtS + TimeSpan.FromDays(6) };
            emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(2), EndTime = dtS + TimeSpan.FromDays(3), TaskName = "Stacy's Task" });
            teams[2].Projects.Add(emp);

            return teams;
        }
    }
    public class Product : INotifyPropertyChanged
    {
        public Product()
        {
            this.Projects = new ObservableCollection&lt;Project&gt;();
        }
        public string PDName { get; set; }
        public ObservableCollection&lt;Project&gt; Projects { get; set; }
        private DateTime _st;
        public DateTime OverallStartTime
        {
            get { return _st; }
            set
            {
                if (this._st != value)
                {
                    TimeSpan dur = this._et - this._st;
                    this._st = value;
                    this.OnPropertyChanged("OverallStartTime");
                    this.OverallEndTime = value + dur;
                }
            }
        }
        private DateTime _et;
        public DateTime OverallEndTime
        {
            get { return _et; }
            set
            {
                if (this._et != value)
                {
                    this._et = value;
                    this.OnPropertyChanged("OverallEndTime");
                }
            }
        }

        #region INotifyPropertyChanged Members

        protected void OnPropertyChanged(string name)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
    public class Project : INotifyPropertyChanged
    {
        public Project() { this.Tasks = new ObservableCollection&lt;Task&gt;(); }
        public string PName { get; set; }
        public ObservableCollection&lt;Task&gt; Tasks { get; set; }
        DateTime _st;
        public DateTime OverallStartTime
        {
            get { return _st; }
            set
            {
                if (this._st != value)
                {
                    TimeSpan dur = this._et - this._st;
                    this._st = value;
                    this.OnPropertyChanged("OverallStartTime");
                    this.OverallEndTime = value + dur;
                }
            }
        }
        DateTime _et;
        public DateTime OverallEndTime
        {
            get { return _et; }
            set
            {
                if (this._et != value)
                {
                    this._et = value;
                    this.OnPropertyChanged("OverallEndTime");
                }
            }
        }

        #region INotifyPropertyChanged Members

        protected void OnPropertyChanged(string name)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
    public class Task : INotifyPropertyChanged
    {
        public string TaskName { get; set; }
        DateTime _st;
        public DateTime StartTime
        {
            get { return _st; }
            set
            {
                if (this._st != value)
                {
                    TimeSpan dur = this._et - this._st;
                    this._st = value;
                    this.OnPropertyChanged("StartTime");
                    this.EndTime = value + dur;
                }
            }
        }
        private DateTime _et;
        public DateTime EndTime
        {
            get { return _et; }
            set
            {
                if (this._et != value)
                {
                    this._et = value;
                    this.OnPropertyChanged("EndTime");
                }
            }
        }

        #region INotifyPropertyChanged Members

        protected void OnPropertyChanged(string name)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
</code></pre>
