Chantal Decraie

Chantal Decraie

  • NA
  • 20
  • 1.6k

How to change innertext of an xml file

Feb 20 2017 7:00 AM
Hi,
 
Now that I can read my xml-file from my richtextbox I would like to change some innertext in the childnodes and whatch the changes in my richtextbox. How should I do this please? Because my code isn't working.
 
 
//Read selected file.
XmlDocument doc = new XmlDocument();
doc.LoadXml(richTextBox1.Text);
XmlNodeList nodeList = doc.DocumentElement.SelectNodes("/AnXMLTestFile/"); //<== error message "Expression must evaluate to a node-set."
//find the node to change the content
//if node is not present, do nothing
foreach (XmlNode xNode in nodeList)
{
if (xNode.ParentNode.Attributes["HeaderBEDocument"].Value != "")
{
doc.SelectSingleNode("Identification").InnerText = "string";
doc.SelectSingleNode("SCI").InnerText = "string";
doc.SelectSingleNode("ReferenceType").InnerText = "string";
doc.SelectSingleNode("CCType").InnerText = "AA";
}
else { } //do nothing
}
 
Can someone help me please?
Thanks in advance. 

Answers (2)