首页 > 其他 > 详细

关于xml文件的使用

时间:2015-10-12 14:15:46      阅读:136      评论:0      收藏:0      [点我收藏+]

 关于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 + @"\xml\Lconfig.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();
        }

关于xml文件的使用

原文:http://www.cnblogs.com/Super-Lily/p/4871416.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!