引用: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; }