c # xml操作 (无法将类型为“System.Xml.XmlComment”的对象强制转换为类型“System.Xml.XmlElement”)

引用:http://topic.csdn.net/u/20080311/16/358d97b9-1e56-4925-aea0-43f9734b3e03.html

foreach (XmlNode xn in nodeList)//遍历所有子节点
{ XmlElement xe = xn as XmlElement;//最好不好用强制转换,建议使用as,这样如果转不过去话,就是null,不会报异常if(xe!=null) //这样判断以下是否为null,或者你可以if(xe==null) return ;直接返回或做其他处理
{ Keyname = xe.Attributes["key"].InnerXml;//键值 switch (Keyname)
{ case"SiteName": xe.Attributes["value"].Value =this.txtSiteName.Text; break; case"Sitecontent": xe.Attributes["value"].Value =this.txtDescription.Text; }
 
posted @ 2012-07-07 22:13  镇水古月  阅读(1138)  评论(0编辑  收藏  举报