I try to find the first attribute in an XML file that contains the string "name" (case insensitve) in it, and then change its value.
Here is an example of my xmls
<CtApproachTypes
DataclassId="1992A9CE-B048-4676-BFD4-FD81F1A65401"
EntityId="1992A9CE-B048-4676-BFD4-FD81F1A65401"
Name="PAR"
Remark="No Remarks"></CT_ApproachTypes>
<MiMissions
DataclassId="C196A66B-4FA1-461C-9EEF-95A4F2085051"
EntityId="C196A66B-4FA1-461C-9EEF-95A4F2085051"
MissionName="Standard"
Visib="1"></MiMissions>
<StSituations
DataclassId="679FAC3C-C9EF-41FD-9A13-957915605F01"
EntityId="679FAC3C-C9EF-41FD-9A13-957915605F01"
Sname="Standard"
Status="C"
Template="1"></StSituations>
I want to be able to change the values of "Name", "MissionName", "Sname" and print them on the console
EDIT
here is my code
public void updateXmlFile(string strFileName)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(strFileName);
string newValue = GetUniqueKey();
XmlNodeList list = doc.SelectNodes("@*");
IEnumerable<XmlNode> filteredList= list.Cast<XmlNode>().Where(item=>item.Value.ToLower().Contains("name"));
foreach (XmlNode n in filteredList)
{
Console.WriteLine("NODES ARE : {0}", n);
}
doc.Save(strFileName);
}
catch (XmlException xex) { Console.WriteLine(xex); }
}
This did not print anything, and I still need to change the original value using the string newValue
source
share