读取XML文件:
using System.Xml;
protected void readXml()
{
try
{
System.Xml.XmlDocument mXmlDoc=new System.Xml.XmlDocument();
mXmlDoc.Load(Server.MapPath("filepath"));
string nettype=mXmlDoc.SelectNodes("//Root/Nettype")[0].InnerText;
int cells=int.Parse(mXmlDoc.SelectNodes("//Root/Cells")[0].InnerText);
XmlNodeList mXmlNodes=mXmlDoc.SelectNodes("//Root/IPlink");
foreach(XmlNode IPlinkchildlNode in mXmlNodes)
{
int icount=int.Parse(IPlinkchildlNode.ChildNodes[2].InnerText);
}
}
catch
{
/*
可能的错误是:1、配置文件不存在
2、配置文件内容被损坏
*/
}
}
xxx.xml
<?xml version="1.0"?>
<Root>
<Nettype>net</Nettype>
<Totalnum>6</Totalnum>
<Cells>2</Cells>
<IPlink>
<Name>站点1</Name>
<IP>192.8.198.1</IP>
<Sequence>1</Sequence>
</IPlink>
<IPlink>
<Name>站点2</Name>
<IP>192.8.198.2</IP>
<Sequence>2</Sequence>
</IPlink>
… …
</Root>