zoukankan      html  css  js  c++  java
  • 网站的配置文件XML读写

    网站的配置信息一般都写入到XML中,以下是简单的对xml的读写操作,仅供参考。

    读操作:
            XmlDocument xmlDoc = new XmlDocument();
                 XmlReaderSettings settings = new XmlReaderSettings();
                 settings.IgnoreComments = true;//忽略文档里面的注释
                 var path = HttpContext.Server.MapPath("../../SiteConfig/Siteconfig.xml");//获取文件路径
                 var myXDocument = XDocument.Load(path);
                 EditWebConfigViewModel siteconfigModel = new EditWebConfigViewModel();
                 siteconfigModel.WebName = myXDocument.Element("SiteConfig").Element("WebName").Value;
                 siteconfigModel.CompanyName = myXDocument.Element("SiteConfig").Element("CompanyName").Value;
                 siteconfigModel.Address = myXDocument.Element("SiteConfig").Element("Address").Value;
                 siteconfigModel.Tel = myXDocument.Element("SiteConfig").Element("Tel").Value;
                 siteconfigModel.Email = myXDocument.Element("SiteConfig").Element("Email").Value;
                 siteconfigModel.RecordNumber = myXDocument.Element("SiteConfig").Element("RecordNumber").Value;
                 siteconfigModel.SeoTitle = myXDocument.Element("SiteConfig").Element("SeoTitle").Value;
                 siteconfigModel.SeoKey = myXDocument.Element("SiteConfig").Element("SeoKey").Value;
                 siteconfigModel.SeoDescription = myXDocument.Element("SiteConfig").Element("SeoDescription").Value;
                 siteconfigModel.Copyright = myXDocument.Element("SiteConfig").Element("Copyright").Value;
    写操作:
             var path = HttpContext.Server.MapPath("../../SiteConfig/Siteconfig.xml");
                    var myXDocument = XDocument.Load(path);
                    myXDocument.Element("SiteConfig").Element("WebName").Value = editWebConfig.WebName;
                    myXDocument.Element("SiteConfig").Element("CompanyName").Value = editWebConfig.CompanyName;
                    myXDocument.Element("SiteConfig").Element("Address").Value = editWebConfig.Address;
                    myXDocument.Element("SiteConfig").Element("Tel").Value = editWebConfig.Tel;
                    myXDocument.Element("SiteConfig").Element("Email").Value = editWebConfig.Email;
                    myXDocument.Element("SiteConfig").Element("RecordNumber").Value = editWebConfig.RecordNumber;
                    myXDocument.Element("SiteConfig").Element("SeoTitle").Value = editWebConfig.SeoTitle;
                    myXDocument.Element("SiteConfig").Element("SeoKey").Value = editWebConfig.SeoKey;
                    myXDocument.Element("SiteConfig").Element("SeoDescription").Value = editWebConfig.SeoDescription;
                    myXDocument.Element("SiteConfig").Element("Copyright").Value = editWebConfig.Copyright;
                    myXDocument.Save(path);
  • 相关阅读:
    Python的可变和不可变类型
    Pycharm设置语法规范快捷键方式
    python学习0305作业
    关于jQuery对象与DOM对象
    ie6下子元素撑大父元素
    Hibernate持久层ORM框架
    基于注解的事务管理
    掌握基于AOP事务管理
    Spring事务管理
    事务保存点savepoint
  • 原文地址:https://www.cnblogs.com/WZH75171992/p/4643267.html
Copyright © 2011-2022 走看看