C#读取一个xml


/// <summary>
    
/// 使用XmlReader构造函数
    
/// </summary>
    public static void UseXmlReader()
    {
        
string sURL = "http://localhost:9058/GameServerInfo/XMLFile.xml";
        
using(XmlReader read=XmlReader.Create(sURL))
        {
            
while(read.Read())
            {
                
switch (read.NodeType)
                {
                    
case XmlNodeType.Element:
                        HttpContext.Current.Response.Write(
string.Format("ElementName->{0} <br />", read.Name));
                        
break;
                    
case XmlNodeType.Text:
                        HttpContext.Current.Response.Write(
string.Format("ElementValue->{0}<br />", read.Value));
                        
break;
                    
case XmlNodeType.CDATA:
                        HttpContext.Current.Response.Write(
string.Format("ElementValue->{0}<br />", read.Value));
                        
break;
                        
//other
                }
            }
        }

posted @ 2009-08-02 17:05  Sum_yang  阅读(146)  评论(0编辑  收藏  举报