【发布时间】:2011-10-19 14:55:06
【问题描述】:
使用XDocument,下面的代码怎么改写?此代码将元素值替换为 strValues。该元素由strKeys 和strXPath = "/root/node/subnode[param1='value1' and param2='value2']" 指定。
public static void ReplaceXmlElement(string strXPath, string[] strKeys, string[] strValues)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(xmlFile.xml);
XmlNode xNode = xDoc.SelectSingleNode(strXPath);
int intTemp = 0;
foreach (XmlNode node in xNode)
{
node.Name.ToString();
if (node.Name == strKeys[intTemp])
{
node.InnerXml = strValues[intTemp];
intTemp++;
}
}
xDoc.Save(xmlFile.xml);
}
【问题讨论】:
标签: c# xml linq-to-xml xmldocument