遍历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()); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Xcode – 如何更改macOS应用程序的显示名称?
- 简单理解Vue条件渲染
- SQLITE – INSERT或UPDATE而不更改ROWID值
- ruby-on-rails – state_machine vs aasm gems for rails r
- 调试 – 使用pgAdmin调试PostgreSQL函数
- quick-cocos2d-x UIScrollView使用
- Flex中解决Parsley框架中注入窗口
- c# – 如何为给定项目禁用NUnit Adapter?
- ruby-on-rails – 参数数量错误?
- c# – XML序列化 – XmlCDataSection为Serialization.XmlTe