加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

遍历XML的一个示例----dhgList

发布时间:2020-12-16 09:30:31 所属栏目:百科 来源:网络整理
导读:http://www.cnblogs.com/xiaobaidhg/archive/2006/07/06/443965.html 1、xml文件MyConfigure.xml ?xml version="1.0" encoding="utf-8" ? IPConfigure IPID id="" IPAddress/IPAddress IPUser/IPUser IPPass/IPPass IPLocalPath/IPLocalPath IPThread/IPThre

http://www.cnblogs.com/xiaobaidhg/archive/2006/07/06/443965.html

1、xml文件MyConfigure.xml

<?xml version="1.0" encoding="utf-8" ?>
<IPConfigure>
<IPID id="">
<IPAddress></IPAddress>
<IPUser></IPUser>
<IPPass></IPPass>
<IPLocalPath></IPLocalPath>
<IPThread></IPThread>
</IPID>
</IPConfigure>

2、遍历该xml文件。
/// <summary>
/// 读入xml的值--dhg 2006-7-6 10:00
/// </summary>
private void MyXmlReader()
{
try
string XMLPath=Application.StartupPath+"MyConfigure.xml";
XmlDocument doc=new XmlDocument();
doc.Load(XMLPath);
XmlNode xnuser=doc.SelectSingleNode("IPID").ChildNodes;//找到所有的IPConfigure下的所有子节点
foreach(XmlNode xn in xnuser) //遍历IPID下所有的节点
XmlElement xe=(XmlElement)xn;
//读取节点中的一个属性
XmlNodeList Ipid=xe.SelectNodes(" /IPID/@id ");
//XmlNode xnuser=doc.SelectSingleNode("IPID");
//string flag=xnuser.Attributes["id"].InnerText;
XmlNodeList ipaddress=xe.GetElementsByTagName("IPAddress");
XmlNodeList ipuser=xe.GetElementsByTagName("IPUser");
XmlNodeList ippass=xe.GetElementsByTagName("IPPass");
XmlNodeList iplocalpath=xe.GetElementsByTagName("IPLocalPath");
XmlNodeList ipthread=xe.GetElementsByTagName("IPThread");
if (Ipid.Count>0)
for(int i=0;i<Ipid.Count;i++)
if(Ipid[i].Value=Ipid.Count) //最后一个节点
this.txtIP.Text=ipaddress[i].InnerText.ToString();
this.txtUser.Text=ipuser[i].InnerText.ToString();
this.txtPass.Text=ippass[i].InnerText.ToString();
this.txtlocalPath.Text=iplocalpath[i].InnerText.ToString();
this.txtChunksCount.Text=ipthread[i].InnerText.ToString();
}
catch(Exception e)
throw new Exception("Exception:{0}: ",e.ToString());
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读