Modify XML existing content in C#

Posted by Nano HE on Stack Overflow See other posts from Stack Overflow or by Nano HE
Published on 2010-03-31T08:03:15Z Indexed on 2010/03/31 8:13 UTC
Read the original article Hit count: 301

Filed under:
|
|
|

Purpose: I plan to Create a XML file with XmlTextWriter and Modify/Update some Existing Content with XmlNode SelectSingleNode(), node.ChildNode[?].InnerText = someting, etc.

After I created the XML file with XmlTextWriter as below.

XmlTextWriter textWriter = new XmlTextWriter("D:\\learning\\cs\\myTest.xml", System.Text.Encoding.UTF8);

I practiced the code below. But failed to save my XML file.

XmlDocument doc = new XmlDocument();
                doc.Load("D:\\learning\\cs\\myTest.xml");

                XmlNode root = doc.DocumentElement;
                XmlNode myNode;

                myNode= root.SelectSingleNode("descendant::books");

....

 textWriter.Close();

 doc.Save("D:\\learning\\cs\\myTest.xml");  

I found it is not good to produce like my way. Is there any suggestion about it? I am not clear about the concepts and usage of both XmlTextWriter and XmlNode in the same project. Thank you for reading and replies.

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml