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");
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。