Best way to read, modify, and write XML

前端 未结 8 1936
灰色年华
灰色年华 2021-02-05 10:39

My plan is to read in an XML document using my C# program, search for particular entries which I\'d like to change, and then write out the modified document. However, I\'ve bec

8条回答
  •  佛祖请我去吃肉
    2021-02-05 11:09

    If you have smaller documents which fit in computers memory you can use XmlDocument. Otherwise you can use XmlReader to iterate through the document.

    Using XmlReader you can find out the elements type using:

    while (xml.Read()) {
       switch xml.NodeType {
         case XmlNodeType.Element:
          //Do something
         case XmlNodeType.Text:
          //Do something
         case XmlNodeType.EndElement:  
          //Do something
       }
    }
    

提交回复
热议问题