问题1:这个应该比较简单了;问题2:在<host1 id="host1" chs_name="主机1" />;主机1是属性chs_name的值,
       要用XmlNode.Attributes["chs_name"]来获得主机1这个值。
       在<host id="host1">主机1</host>;主机1是XmlNode.InnerText值,而不是
       属性值。问题3:在把Xml加载到TreeView时,没生成一个TreeNode节点,就把id属性写到对应的
        TreeNode节点的Tag属性中,当点击treeView的时候就可以读tag值来得到id

解决方案 »

  1.   

    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q317597
      

  2.   

    那为什么用 str2=xmlroot.Attributes["id"]; 总是编译出错“error CS0029: 无法将类型“System.Xml.XmlAttribute”隐式转换为“string””;
    而换成 str2=xmlroot.Attributes["id"].ToString(); 运行时就会出错:
    未处理的“System.NullReferenceException”类型的异常出现在 mystudy1.exe 中。
    其他信息: 未将对象引用设置到对象的实例。
      

  3.   

    http://forums.zol.com.cn/new/static_book2/137/501/137_3501.shtml
    和楼主一样的问题,楼主可以看看.
      

  4.   

    那为什么用 str2=xmlroot.Attributes["id"]; 总是编译出错“error CS0029: 无法将类型“System.Xml.XmlAttribute”隐式转换为“string””;
    ------------------------------------------------------------
    一定要加ToString()而换成 str2=xmlroot.Attributes["id"].ToString(); 运行时就会出错:
    未处理的“System.NullReferenceException”类型的异常出现在 mystudy1.exe 中。
    --------------------------------
    你的元素读取可能有问题,或者文件不是你描述的那样