var books = new[] {
new {Title="Ajax in Action", Publisher="Manning", Year=2005 },
new {Title="Windows Forms in Action", Publisher="Manning", Year=2006 },
new {Title="RSS and Atom in Action", Publisher="Manning", Year=2006 }
};
// Build the XML fragment based on the collection
XElement xml = new XElement("books",
from book in books
where book.Year == 2006
select new XElement("book",
new XAttribute("title", book.Title),
new XElement("publisher", book.Publisher)
)
);
// Dump the XML to the console
Console.WriteLine(xml);
Console.ReadKey();
Linq to xml demo
最新推荐文章于 2024-10-18 18:49:38 发布