private void Load()
{
XmlDocument doc = new XmlDocument();
doc.Load("MyXml.xml");
//read the root node
XmlNode root = doc.DocumentElement;
Debug.Assert(root != null, "Setting file is not valid.");
//read a node under a node with given node name
XmlNode xn = root.SelectSingleNode("Database");
Debug.Assert(xn != null, "Setting file is not valid.");
XmlElement xe = (XmlElement)xn;
Debug.Assert(xe.Attributes.Count > 0, "Setting file is not valid.");
//read a attribute with a given attribute name, as <NodeName AttrName1="1" AttrName2="2" />
string s = xe.GetAttribute("FileName");
xn = root.SelectSingleNode("IgnoreFields");
XmlNodeList xnl = xn.ChildNodes;
foreach (XmlNode xnf in xnl)
{
xe = (XmlElement)xnf;
AList.Add(xe.Attributes[0].Name, xe.Attributes[0].Value);
}
}
private void Save()
{
XmlDocument doc = new XmlDocument();
doc.Load("MyXml.xml");
XmlNode root = doc.DocumentElement;
Debug.Assert(root != null, "Setting file is not valid.");
XmlNode xn = root.SelectSingleNode("Database");
Debug.Assert(xn != null, "Setting file is not valid.");
XmlElement xe = (XmlElement)xn;
Debug.Assert(xe.Attributes.Count > 0, "Setting file is not valid.");
//write a attribute with a given attribute name, as <NodeName AttrName1="1" AttrName2="2" />
xe.SetAttribute("FileName", "3");
XmlNode xn = root.SelectSingleNode("Compared");
Debug.Assert(xn != null, "Setting file is not valid.");
XmlNode node = doc.CreateNode(XmlNodeType.Element, "Table", null);
XmlElement xe = (XmlElement)node;
xe.SetAttribute(StationName, "Y");
xn.AppendChild(xe);
doc.Save("MyXml.xml");
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。