读取XML文件

时间:2017-11-28 18:24:12   收藏:0   阅读:243

XmlDocument xmlDoc = new XmlDocument();
string filePath = Path.Combine(AppContext.BaseDirectory, "Configuration", sDir, string.Format("{0}.xml", sXmlName));

StringBuilder builder = new StringBuilder();
using (FileStream fs = File.Open(filePath, FileMode.OpenOrCreate))
{
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
{

builder.Append(sr.ReadToEnd());
}
}
if (builder.Length > 0)
xmlDoc.LoadXml(builder.ToString());      //
return xmlDoc;

注意:

xmldoc.load可以加载文件,比如:xmldoc.load("c:\\a.xml");
而xmldoc.loadXML是加载xml格式的字符串,比如:xmldoc.loadXML("<aab>aaa</aab>")

原文:http://www.cnblogs.com/DSC1991/p/7911215.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!