parse xml children nodes

What is the best way to parse XML children nodes into a specific list? This is a small example of the XML.

<Area Name="Grey Bathroom" IntegrationID="3" OccupancyGroupAssignedToID="141">
  <Outputs>
  <Output Name="Light/Exhaust Fan" IntegrationID="46" OutputType="NON_DIM" Wattage="0" /> 
  </Outputs>
</Area>

I want to create a list or something that will be called the Area Name and hold the information of the Output Name and IntegrationID. So I can call the list and pull out the Output Name and IntegrationID.

I can create a list of all Area Names and then a list of Outputs but cannot figure out how to create a list that will be called "Grey Bathroom" and hold the output "Light/Exhaust Fan" with an ID of 46.

Answers


XDocument doc = XDocument.Load(@"E:\a\b.xml");
        List<Area> result = new List<Area>();
        foreach (var item in doc.Elements("Area"))
        {
            var tmp = new Area();
            tmp.Name = item.Attribute("Name").Value;
            tmp.IntegrationID = int.Parse(item.Attribute("IntegrationID").Value);
            tmp.OccupancyGroupAssignedToID = int.Parse(item.Attribute("OccupancyGroupAssignedToID").Value);

            foreach (var bitem in item.Elements("Outputs"))
            {
                foreach (var citem in bitem.Elements("Output"))
                {
                    tmp.Outputs.Add(new Output
                    {
                        IntegrationID = int.Parse(citem.Attribute("IntegrationID").Value),
                        Name = citem.Attribute("Name").Value,
                        OutputType = citem.Attribute("OutputType").Value,
                        Wattage = int.Parse(citem.Attribute("Wattage").Value)
                    });
                }
            }
            result.Add(tmp);
        }

public class Area
{
    public String Name { get; set; }
    public int IntegrationID { get; set; }
    public int OccupancyGroupAssignedToID { get; set; }
    public List<Output> Outputs = new List<Output>();
}

public class Output
{
    public String Name { get; set; }
    public int IntegrationID { get; set; }
    public String OutputType { get; set; }
    public int Wattage { get; set; }
}

Need Your Help

Is there anyway to view memcache data in google app engine?

python google-app-engine memcached

Basically what I want to do is see the raw data of memcache so that I can see how my data are being stored.

200 OK Error AJAX - MYSQL request + “undefined” return

php mysql ajax

I'm trying to implement an AJAX application where the user enters the id of a user, all the information associated with the id will be filled in the remaining text fields. For example, when the user

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.