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
最新推荐文章于 2025-12-12 16:04:13 发布
本文演示了如何从图书集合构建XML片段,并通过代码实现将数据转换为XML格式的过程。
156

被折叠的 条评论
为什么被折叠?



