1
XDocument
을 사용하면 어떻게 다음 코드를 다시 작성할 수 있습니까? 이 코드는 요소 값을 strValues
으로 바꿉니다. 요소는 strKeys
및 strXPath = "/root/node/subnode[param1='value1' and param2='value2']"
으로 지정됩니다.XmlDocument 대신 XDocument로 요소 바꾸기
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);
}