It is required to add a child node to the specified node.
There are no exceptions, but the data.xml file data.xml not contain a connected node.
Code:

 XmlTextReader reader = new XmlTextReader(openFileDialog1.FileName); XmlDocument doc = new XmlDocument(); doc.Load(openFileDialog1.FileName); while (reader.Read()) { if(textBox1.Text == reader.Name) { XmlNode root = doc.ReadNode(reader); XmlElement elem = doc.CreateElement("test_node"); elem.InnerText = "test_text"; root.AppendChild(elem); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlWriter writer = XmlWriter.Create(path +"\\data.xml", settings); doc.Save(writer); } } 
  • I clarify. The data.xml file itself is created, but its structure coincides with the doc structure, that is, the new node is not displayed - Xymis
  • The ReadNode method creates a new node. But it is not inserted into the DOM tree! Either add it using AppendChild , or get it using SelectSingleNode , for example. - Alexander Petrov
  • 2
    Remove the simultaneous use of XmlTextReader and XmlDocument . Use one thing. And best of all, take the LinqToXml XDocument / XElement classes. - Alexander Petrov
  • Sasha, you are the best: - * - Xymis

0