I have an xml file like this one:
<root>
<sub>
<name>Al</name>
<code>001</code>
</sub>
<sub>
<name>John</name>
<code>002</code>
</sub>
and a List<string> lName= new List<string>(new string[] { "Jack", "John"});
I want to edit "John" node, add "Jack" node and leave "Al" node as it is. What I did is:
System.Xml.XmlNodeList nodeNameList = FileXml.SelectNodes(@"//*[contains(name(),'name')]");
foreach (string name in lName)
{
System.Xml.XmlNode nodeName=FileXml.SelectSingleNode("//root/sub/name");
if (nodeName.InnerText == name)
{
//add
}
else
{
//edit
}
But it doesn't work. I thought that XmlNodeList works as a normal list but it doesn't. Can someone help me?