日期:2014-05-17 浏览次数:20956 次
<?xml version="1.0" encoding="utf-8"?>
<items>
<item>
<title>毛著</title>
<author>毛泽东</author>
<price>10.00</price>
</item>
<item>
<title>流浪记</title>
<author>三毛</author>
<price>20</price>
</item>
</items>
static void Main(string[] args)
{
XElement element = XElement.Load("test.xml");
IEnumerable result = from p in element.Elements("item")
select p;
foreach (XElement el in result)
{
if (el.Elements("title").FirstOrDefault().Value == "流浪记")
{
el.Elements("price").FirstOrDefault().SetValue("20");