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

原文地址:https://www.cnblogs.com/lgxll/p/2549563.html