这里介绍一种读取xml文档的方法,示例中用的是 xmltextreader 函数,每执行 read() 一次,读取一行.
using system.xml;
public ksbmconfig readconfig(string xmlconfigfile)
{
ksbmconfig _conf = new ksbmconfig ();
try
{
// open an xml file
system.xml.xmltextreader reader;
reader = new system.xml.xmltextreader(xmlconfigfile);
while ( reader.read() )
{
if((reader.nodetype == xmlnodetype.endelement)
&&(reader.name == "ksbm"))
{
break;
}
if(reader.isstartelement ("serverpath"))
{
reader.read ();
_conf.serverpath = reader.value ;
}
else if(reader.isstartelement ("smtpserver"))
{
reader.read ();
_conf.smtpserver = reader.value ;
}
else if(reader.isstartelement ("connectstring"))
{
reader.read ();
_conf.connectstring = reader.value ;
}
}
return _conf;
}
catch
{
_conf.connectstring = "";
_conf.serverpath = "";
_conf.smtpserver = "";
return _conf;
}
finally
{
}
}
新闻热点
疑难解答