More Linq to Xml

by sunil ravulapalli /31. August 2011 16:35 /c# /Comments (0)

  
    1
    
      
        mr
      
      
        mr2
      
    
  

  
    2
    
      
        mr
      
    
  

  
    3
    
    
  


This is how the query looks:

IEnumerable people =
from person in data.Elements("person")
select new Person
{
	id = (int)person.Element("id"),
	positions = (
				from position in person.Elements("positions").Elements("position")
				select new Position { title = position.Element("title").Value } 
			 ).ToList()
};

The classes look like this:

public class Person
{
	public int id { get; set; }
	public List positions { get; set; }
}

public class Position
{
	public string title { get; set; }
}
blog comments powered by Disqus