<Application version="1.0">
    <Global CurAppEntry="初始安装单位" />
    <AppRegistry>
        <AppEntry Name="单位一" PKID="" DepName="名称一"  />
        <AppEntry Name="单位二" PkID="" DepName="名称二"  /> 
   </AppRegistry>
    <AppRegistryBak>
        <AppEntry Name="单位一" PKID="" DepName="名称一" />
    </AppRegistryBak>
</Application>我想通过列表框读取<AppRegistry>下Name节点值,列表值为 单位一,单位二可以切换列表。通过文本更新DepName值请问如何做?

解决方案 »

  1.   

    XmlDocument xmldoc = new XmlDocument();
      xmldoc.Load(路径);
      XmlNode mainnode = xmldoc.SelectSingleNode("Application");
      XmlNode subnode = mainnode.SelectSingleNode("AppRegistry");
    for(int i=0;i<subnode.ChildNodes.count;i++)
    {
    subnode.ChildNodes[i].GetAttribute(Name);//取“单位"
    }
     是要将单位都取出来吧
     
      

  2.   

    XmlDocument xmldoc = new XmlDocument();
      xmldoc.Load(路径);
      XmlNode mainnode = xmldoc.SelectSingleNode("Application");
      XmlNode subnode = mainnode.SelectSingleNode("AppRegistry");
    for(int i=0;i<subnode.ChildNodes.count;i++)
    {
    subnode.ChildNodes[i].GetAttribute(Name);//取“单位"
    }
     是要将单位都取出来吧
     
      

  3.   

    XmlDocument xmldoc = new XmlDocument();
      xmldoc.Load(路径);
      XmlNode mainnode = xmldoc.SelectSingleNode("Application");
      XmlNode subnode = mainnode.SelectSingleNode("AppRegistry");
    for(int i=0;i<subnode.ChildNodes.count;i++)
    {
    subnode.ChildNodes[i].GetAttribute(Name);//取“单位"
    }
     是要将单位都取出来吧
     
      

  4.   

    读取值绑定到下拉框
    再修改xml
    XMLDocument doc=new XMLDocument();
    doc.Load("");
    foreach (XmlNode node in doc.GetElementsByTagName("AppRegistry")) 
    {}
      

  5.   

    GetAttribute找不到方法,先读取信息,在更新内容
      

  6.   


    public static string GetConfigValue(string key)
            {
                string result = string.Empty;
                try
                {
                    var doc = XDocument.Load("xmlfile1.xml");
                    var q = from p in doc.Root.Elements("AppRegistry").Elements() select p;
                    if (q.Count() > 0)
                    {
                        foreach (var item in q)
                        {
                            if (string.Compare(key, item.FirstAttribute.Value, true) == 0)
                            {
                                result = item.LastAttribute.Value;
                                break;
                            }
                        }
                    }
                }
                catch
                {
                }
                return result;
            }
    注意:需要添加对
    using System.Xml.Linq;
    using System.Linq;
    命名空间的引用
    把上面的xmlfile1.xml改为你的文件名
    string value = GetConfigValue("单位一");