• 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();
                        }
                    }

  • 相关阅读:
    《硅谷之谜》读书笔记
    Google的Bigtable学习笔记(不保证正确性)
    软件开发到底是怎么一回事呢?
    如何控制自己之2016个人目标管理
    如何自适应网页的协议(http/https/……)
    数据库时间戳设计
    AngularJS-Controller的使用-读书笔记
    FIM相关报错汇总
    iPad上的Cookie到底有多长?
    【solr】join查询,跟mysql的join不一样
  • 原文地址:https://www.cnblogs.com/lgxll/p/2549563.html
Copyright © 2020-2023  润新知