关于xml文件的使用
首先引用XML,即:using System.XML
例:Lconfig.xml
写:
/// <summary>
/// 写入配置文件
/// </summary>
public void WriteLConfig( string Name, string IP, string Pass)
{
XmlTextWriter xtw = new XmlTextWriter( Application .StartupPath + "\xml\Lconfig.xml" , Encoding.UTF8);
xtw.WriteStartDocument();
xtw.WriteStartElement( "SqlServer" );
xtw.WriteElementString( "Name" , Name);
xtw.WriteElementString( "IP" , IP);
xtw.WriteElementString( "Pass" , Pass);
xtw.WriteEndElement();
xtw.WriteEndDocument();
xtw.Close();
}
读:
/// <summary>
/// 读配置文件
/// </summary>
public void readXml()
{
XmlTextReader xtr = new XmlTextReader( Application .StartupPath + @"xmlLconfig.xml" );
while (xtr.Read())
{
if (xtr.NodeType == XmlNodeType .Element)
{
if (xtr.LocalName == "Name" )
{
LName = xtr.ReadString();
}
if (xtr.LocalName == "IP" )
{
LIP = xtr.ReadString();
}
if (xtr.LocalName == "Pass" )
{
LPass = xtr.ReadString();
}
}
}
xtr.Close();
}