//MY XML FILE STRUCTURE
<items>
<item>
<itemID>1</itemID>
<isGadget>True</isGadget>
<name>Star Wars Figures</name>
<text1>LukeSkywalker</text1>
</item>
</items>
//TO READ DATA FROM XML BY ITEMID
XDocument xmlDoc = XDocument.Load(HttpContext.Current.Server.MapPath("data.xml"));
var items = from item in xmlDoc.Descendants("item")
where item.Element("itemID").Value == itemID
select new
{
itemID = item.Element("itemID").Value,
isGadget = bool.Parse(item.Element("isGadget").Value),
name = item.Element("name").Value,
text1 = item.Element("text1").Value,
}
foreach (var item in items)
{
....
}
Làm cách nào để cập nhật dữ liệu XML theo itemID? Cảm ơn!Cập nhật XML bằng C# bằng cách sử dụng Linq
Tôi không hiểu tại sao các câu hỏi LINQ-to-XML lại phổ biến như vậy vào lúc này. Câu trả lời là _right here_. http://msdn.microsoft.com/en-us/library/bb387087.aspx – Gusdor