Hi all,
I wanna create a method which receives the xml file name, then read it and change the values...
I have different xml files, each one has different nodes, so I just want a simple method that reads any xml file and iterates through all the nodes, and change all the values.
I've tried some code
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlFile); string var = "//"+xmlDoc.DocumentElement.Name; XmlNodeList nodeList = xmlDoc.SelectNodes(var); foreach(XmlNode node in nodeList) { foreach(XmlNode childNode in node.ChildNodes) { switch (childNode.NodeType) { case XmlNodeType.Element: childNode.InnerText = nodeValue; break; case XmlNodeType.Attribute: childNode.InnerText = nodeValue; break; } } }
But only works with xml like this:
<value><value1></value1> <value2></value2> ...</value>
And I need a dinamic method for iterating over xml like this:
<value><value1><value1.1></value1.1><value1.2></value1.2></value1> <value2><value2.1><value2.1.1></value2.1.1></value2.1></value2> ...</value>