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