winform程序 读、写xml文件

来源:互联网 发布:谷歌读屏软件下载5.02 编辑:程序博客网 时间:2024/05/22 06:34

有用到先上代码,后面总结相关知识,,,


创建:

  1. XmlDocument xmlDoc = new XmlDocument();    
  2.             //创建类型声明节点    
  3.             XmlNode node=xmlDoc.CreateXmlDeclaration("1.0","utf-8","");    
  4.             xmlDoc.AppendChild(node);    
  5.             //创建根节点    
  6.             XmlNode root = xmlDoc.CreateElement("User");    
  7.             xmlDoc.AppendChild(root);    
  8.             CreateNode(xmlDoc, root, "name""xuwei");    
  9.             CreateNode(xmlDoc, root, "sex""male");    
  10.             CreateNode(xmlDoc, root, "age""25");  

读取:3种方法

1.XmlDocument

2.XmlTextReader

3.linq to xml