xml 的读写

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml; namespace COMMON
{
public class XmlHelperClass
{
public void Read()
{
Dictionary<string, string> m_FontList = new Dictionary<string, string>();
try
{
XmlDocument doc = new XmlDocument(); // 获得配置文件的全路径  
string strFileName = "Font.xml";
doc.Load(strFileName);
XmlNode node = doc.GetElementById("font");
XmlNodeList nodes = node.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
if (nodes[i].NodeType == XmlNodeType.Element)
{
m_FontList[nodes[i].Name] = nodes[i].InnerText;
}
}
}
catch (Exception e)
{
throw e;
}
} public void Write(string tagName, string value)
{
XmlDocument doc = new XmlDocument(); //获得配置文件的全路径  
string strFileName = @"C:\Program Files\IIS Express/Font.xml";
doc.Load(strFileName);
XmlNode node = doc.GetElementById("font");
XmlNodeList nodes = node.ChildNodes;
for (int i = 0; i < nodes.Count; i++)
{
if (nodes[i].Name.Equals(tagName))
{
nodes[i].InnerText = value;
}
}
try
{
//保存上面的修改  
doc.Save(strFileName); }
catch (Exception e)
{
throw e;
}
}
}
}

  

上一篇:Xamarin.Android 入门实例(4)之实现对 SQLLite 进行添加/修改/删除/查询操作


下一篇:代码漏洞扫描描述Cross Site History Manipulation解决办法[dongcoder.com]