posts - 124,  comments - 29,  trackbacks - 0

XML文档如下:
<?xml version="1.0" encoding="utf-8"?>
<ftpHelp>
  <ftpServer1 NetName="ne1" ServerIP="www.whvideo.cn" ServerPath="/logfiles/W3SVC180" LocalPath="D:/MyWork/download1" UserName="antistone" Password="loginlogout" TimeInterval="15">
  </ftpServer1>
  <ftpServerne2 NetName="ne2" ServerIP="ftp.sjtu.edu.cn" ServerPath="/html/css" LocalPath="D:/MyWork/download2" UserName="" Password="" TimeInterval="15" />
  <ftpServerne3 NetName="ne3" ServerIP="219.231.160.2" ServerPath="/111" LocalPath="D:/MyWork" UserName="lm" Password="113762" TimeInterval="15" />
</ftpHelp>

XML文档中生成节点
         XmlDocument xmlDoc = new XmlDocument();
          xmlDoc.Load("FtpHelp.xml");
          XmlNode node = xmlDoc.SelectSingleNode("ftpHelp");
          String cndName = "ftpServer" + this.txtNeName.Text;
          XmlElement cnd = xmlDoc.CreateElement(cndName);
          cnd.SetAttribute("NetName", txtNeName.Text);
          cnd.SetAttribute("ServerIP", txtServerIP.Text);
          cnd.SetAttribute("ServerPath", txtSerPath.Text);
          cnd.SetAttribute("LocalPath", txtLocalPath.Text);
          cnd.SetAttribute("UserName", txtUserName.Text);
          cnd.SetAttribute("Password", txtPassword.Text);
          cnd.SetAttribute("NetName", txtNeName.Text);
          cnd.SetAttribute("TimeInterval", txtTimeInterval.Text);
          node.AppendChild(cnd);
          xmlDoc.Save("FtpHelp.xml");

xml文档中遍历查询节点

            String neName = txtNeName.Text;
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("FtpHelp.xml");
            XmlNode node = xmlDoc.SelectSingleNode("ftpHelp");
            foreach (XmlNode nd in node.ChildNodes)
            {
                if (nd.Attributes["NetName"].Value == neName)
                {
                  MessageBox.Show("该网元已注册,注册信息为:","提示");
                  this.plNeInfo.Visible = true;
                  txtServerIP.Text = nd.Attributes["ServerIP"].Value;
                  txtSerPath.Text = nd.Attributes["ServerPath"].Value;
                  txtLocalPath.Text=nd.Attributes["LocalPath"].Value;
                  txtUserName.Text = nd.Attributes["UserName"].Value;
                  txtPassword.Text = nd.Attributes["Password"].Value;
                  txtTimeInterval.Text = nd.Attributes["TimeInterval"].Value;
                  this.btnAdd.Visible = false;
                  return;
                }
            }
            MessageBox.Show("该网元不存在,请注册","提示");



 private List<NeFtpInfo> GetXmlInfo(String fileName,List<String> neNameList)
        {
            if (neNameList!=null)
            {
                List<NeFtpInfo> neInList = new List<NeFtpInfo>();
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);
                XmlNode node = xmlDoc.SelectSingleNode("ftpHelp");

                for (int i = 0; i < neNameList.Count; i++)
                {
                    NeFtpInfo ni = new NeFtpInfo();
                    String neName = neNameList[i];
                    int j = 0;
                    for (j = 0; j < node.ChildNodes.Count; j++)
                    {
                        XmlNode nd = node.ChildNodes[j];
                        if (nd.Attributes["NetName"].Value == neName)
                        {
                            ni.NeName = neName;
                            ni.ServerIP = nd.Attributes["ServerIP"].Value;
                            ni.ServerPath = nd.Attributes["ServerPath"].Value;
                            ni.LocalPath = nd.Attributes["LocalPath"].Value;
                            ni.UserName = nd.Attributes["UserName"].Value;
                            ni.Password = nd.Attributes["Password"].Value;
                            ni.IntervalTime = nd.Attributes["TimeInterval"].Value;
                            neInList.Add(ni);
                            break;
                        }
                    }
                    if (j == node.ChildNodes.Count)
                    {
                        MessageBox.Show("网元" + neName + "没有注册过相关信息", "提示");
                    }
                }
                return neInList;
            }
            else
            {
                return null;
            }
        }

posted on 2008-09-25 15:41 天书 阅读(144) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2008年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用链接

留言簿(5)

随笔档案

文章分类

文章档案

好友的Bolg

搜索

  •  

最新评论

阅读排行榜

评论排行榜