网站的配置文件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);
时间: 2024-10-31 13:58:57

网站的配置文件XML读写的相关文章

配置文件的读写(转载自逆心)

配置文件的读写 System.ConfigurationManager类用于对配置文件的读取.其具有的成员如下: 一.AppSettings AppSetting是最简单的配置节,读写非常简单. 名称 说明 AppSettings 获取当前应用程序默认配置的 AppSettingsSection 数据 ConnectionStrings 获取当前应用程序默认配置的 ConnectionStringsSection 数据 <?xml version="1.0" encoding=&

C# XML读写实例

一.使用System.Xml 实例:完成如下格式配置文件的读写操作: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE doc[]> <root> <DatabaseInfo> <HostName>127.0.0.1</HostName> <DatabaseName>orcl</DatabaseName> <UserN

配置文件的读写

System.ConfigurationManager类用于对配置文件的读取.其具有的成员如下: 一.AppSettings AppSetting是最简单的配置节,读写非常简单. 名称 说明 AppSettings 获取当前应用程序默认配置的 AppSettingsSection 数据 ConnectionStrings 获取当前应用程序默认配置的 ConnectionStringsSection 数据 <?xml version="1.0" encoding="utf

关于Spring配置文件xml文档的schema约束

最开始使用spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例. [html] view plain copy print? <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:m

XML读写

private string fileName = HttpContext.Current.Server.MapPath("~/Student.xml"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetAllStudent(); } } private void GetAllStudent() { ddlStudent.Items.Clear(); XmlDocument do

unity3d里的XML读写示例

关于U3D里面XML读写办法,谢谢刘老师的指导(刘国栋) 代码: /**Project name:*    *Author:*    *Version:*    *Description:*    */ using UnityEngine;using System.Collections;using System.Xml;using System.Xml.Serialization;using System.IO;using System.Text;using System.Security.C

【Python】Python XML 读写

class ACTIVE_FILE_PROTECT_RULE_VIEW(APIView): renderer_classes = (JSONRenderer, BrowsableAPIRenderer) parser_classes = (JSONParser,) def post(self, request): from datetime import datetime from django.utils import timezone from django.utils.timezone i

C语言ini格式配置文件的读写

依赖的类 1 /*1 utils.h 2 *# A variety of utility functions. 3 *# 4 *# Some of the functions are duplicates of well known C functions that are not 5 *# standard. 6 *2 License 7 *[ 8 *# Author: Werner Stoop 9 *# This software is provided under the terms of

.net 生成网站地图 sitemap.xml

1.此处为Demo,借鉴别人的生成 xml //创建xml文件方法一 protected void btn1_OnClick(object sender, EventArgs e) { XmlText xmltext; XmlDocument xmldoc = new XmlDocument(); //加入XML的声明段落 XmlNode xmlnode = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null); xm