首先,需要添加XML支持,即在C#中即using System.Xml;然后,只是给出一个简单的实例,供大家参考,实例有丰富的注释
//定义XML文档并载入
XmlDocument xmlDoc = new XmlDocument();
string str = "RadarParameter.xml";
xmlDoc.Load(@str);
//定义一个xml元素并用其获取xml根节点
XmlElement root = xmlDoc.DocumentElement;
//定义一个xml元素以用于后面的操作
//这是获取一个元素的过程,用了两次SelectSingleNode是因为xml表是那样的
XmlElement temp = (XmlElement)root.SelectSingleNode("rdTargetInfo");
temp = (XmlElement)temp.SelectSingleNode("CLSinformation");
//读取xml的某个节点
string s = temp.GetAttribute("remark");
//将读取的String显示到label上
label1.Text = s;
//改写这个value
temp.SetAttribute("remark", "我自己胡写着测试的");
//写完之后要保存才能生效
xmlDoc.Save(@str);
//将读取的String显示到label上
label1.Text = s;