打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用XML文件保存应用程序配置
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");
    }


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C#:XML操作类
C#操作XML小结
怎样在C#里对xml文件进行修改,新增,删除,插入操作?
VB.NET中操作xml文件
C#读写xml文件(2)
xmlnode 的value与innertext区别
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服