I have this code to Load xml files that I am not sure of if it is complete. This is my code.
public void updateXML(string xmlFile, string chooseNode, string chooseSingleNode, string newNode, string selectedCategory)
{
XmlDocument xml = new XmlDocument();
xml.Load(xmlFile);
foreach (XmlElement element in xml.SelectNodes(chooseNode))
{
foreach (XmlElement element1 in element)
{
if (element.SelectSingleNode(chooseNode).InnerText == selectedCategory)
{
XmlNode newvalue = xml.CreateElement(newNode);
newvalue.InnerText = "MODIFIED";
element.ReplaceChild(newvalue, element1);
xml.Save(xmlFile);
}
}
}
Below is the method that I use in the end, where I set xmlfile and such. (the updateXML method is in "data.cs", which is called on from the repository.
public void editCategory(string newNode)
{
string xmlFile = "Category.xml";
string chooseNodes = "ArrayOfCategory/Category";
string chooseSingleNode = "//Name";
string selectedCategory = "News";
repository.Update(xmlFile, chooseNodes, newNode, chooseSingleNode, selectedCategory);
}
I am unsure of what to put in the diffrent Nodes etc, the code above I found here on Stackoverflow. - Below is my XMLfile that I want to edit.
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfCategory xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Category>
<Id>6b30511d-2cd1-4325-ad73-7b905f76ffc0</Id>
<Name>News</Name>
</Category>
<Category>
<Id>516401f4-b45c-46ef-b8f4-9d05021ae794</Id>
<Name>Pods</Name>
</Category>
<Category>
<Id>0c9cd216-86cf-4a62-884c-1b428150ebac</Id>
<Name>Pods</Name>
</Category>
</ArrayOfCategory>
I would really appreciate your help.