I have following xml which same child element (Filed) and I want to get value from each Child element.
Sameple XML
<root xmlns="">
<books cat="F1" ISBN="01F187597" genre="Programming">
<Field name="Title" val="XML" />
<Field name="Publish Date" val="20010424" />
<Field name="Price" val="43.00" />
</books>
</root>
Code
XDocument xdoc = XDocument.Load("c:\\test6.xml");
var booksData = from book in xdoc.Descendants("root")
//I guess create this and do something with it
// let fieldElements = book.Descendants("Field")
select new Book
{
cat = book.Element("books").Attribute("cat").Value
,ISBN = book.Element("books").Attribute("ISBN").Value
,genre = book.Element("books").Attribute("genre").Value
,Price = "?"
,PublishDate="?"
,Title="?"
};
Book Class
public class Book
{
public string cat {get;set;}
public string ISBN {get;set;}
public string genre {get;set;}
public string Title {get;set;}
public string PublishDate {get;set;}
public string Price { get; set; }
}