0
我想将元素添加到与所述条件的XML文件中的XML查询:LINQ成与其中具有属性子句(“ID”)值==“1”
like where attribute("id").value=="1"
在此代码的where
条款无效:
string xmlFilePath = MapPath("Employees.xml");
XDocument xmlDoc = XDocument.Load(xmlFilePath);
try
{
xmlDoc.Element("employees").Element("employee")
.Where(employee => employee.Attribute("id").Value == "2").FirstOrDefault())
.Add(new XElement("city", "welcome"));
xmlDoc.Save(xmlFilePath);
}
catch (XmlException ex)
{
//throw new XmlException
}
我很抱歉,但我不明白的问题。你能澄清它吗?谢谢。 – 2011-04-27 12:28:00