创建XML:
XmlDocument document=new XmlDocument();
XmlNode node=document.CreateXmlDeclaration("1.0","utf-8",null);
XmlElement element=document.CreateElement("Root");//建立根节点
XmlElement element2=document.CreateElement("FirstRoot");
element2.SetAttribute("name",value);//设置其属性
element.AppendChild(element2);//子节点1
element2.InnerText="";//赋值
.......
document.Save(path);//保存到path路径上。
操作XML节点:
XmlDocument document=new XmlDocument();
document.LayoutXml(path);path//config文件路径
//the first method to visit the node
XmlElement element=(XmlElement)document.SelectSingleNode("//FirstRoot");
string aaa=element.InnerText;
//the second method to visit the node
XmlNode node=document.SelectSingleNode("Root/FirstRoot");
....
//visit the attribute
string bbb=node.Attribute["name"].Value;