zoukankan      html  css  js  c++  java
  • C# 获取xml里的值

     XmlDocument xmldoc = new XmlDocument();
                    string path = ApplicationPath;
                    path = path.Substring(0, path.LastIndexOf(@"\"));
                    path = path.Substring(0, path.LastIndexOf(@"\"));
                    path = path + @"\XMLLocalFile.xml";
                    xmldoc.Load(path);
                    int isChoice = -1;
                    string systemName = cboSystemName.Text.Trim();
                    txtServer.Text = cboSystemName.SelectedValue.ToString().Trim();
                    bool bl = false;
                    XmlNode root = xmldoc.SelectSingleNode("SystemName");
                    for (int i = 0; i < root.ChildNodes.Count; i++)
                    {
                        foreach (XmlAttribute att in root.ChildNodes[i].Attributes)
                        {
                            int findid = att.Name.IndexOf("ID");
                            if (findid > 1)
                            {
                                if (att.Value == systemName)
                                {
                                    isChoice = i;
                                    bl = true;
                                    break;
                                }
                            }
                        }
                        if (bl == true)
                        {
                            break;
                        }
                    }

                    if (isChoice == -1)
                    {
                        MessageBox.Show("配置文件找不到" + systemName + "的本地文件配置信息", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);

                    }
                    foreach (XmlAttribute att2 in root.ChildNodes[isChoice].Attributes)
                    {
                        int findid = att2.Name.IndexOf("ID");
                        if (findid < 0)
                        {
                            txtLocation.Text = (att2.Value).Trim();
                        }
                    }

  • 相关阅读:
    方法的重载
    this用法
    简单的随机数 代码和笔记
    java内存简单剖析
    day 28
    day 27
    day 26
    day 25
    day 24
    day 23
  • 原文地址:https://www.cnblogs.com/lgxll/p/2549563.html
Copyright © 2011-2022 走看看