upup!没人知道吗?高手哪里去了?

解决方案 »

  1.   

    使用System.xml名字空间下的xmldocument类来操作就可以。
    通过xpath来搜索到这个key的位置,然后读出来value的值。then ok.剧简单
    string key="//cccc[@key='abc']"
    XmlNode mNode=xml.DocumentElement.SelectSingleNode(key);
    然后这个节点的东东都在mNode中。
      

  2.   

    谢谢!以下问题:
    XmlDocument doc = new XmlDocument();
    doc.Load(Server.MapPath("Web.xml"));
    Response.Write("doc.Attributes.Count == "+doc.Attributes.Count);
    空指针错误:未将对象引用设置到对象的实例。 
    感觉是Load不上,但打印doc.BaseURI则可以打印出来,就是说找到这个文件了,为什么还不能操作?
      

  3.   

    MapPath的位置指定正确,load是没有问题的。或者直接通过
    doc.Load(Server.MapPath("\\1.xml"));找wwwroot目录
    给你个例子自己研究吧
    XmlDocument doc = new XmlDocument();
    doc.Load(Server.MapPath("\\1.xml"));
    string key="//cccc[@key='edf']";
    XmlNode mNode=doc.DocumentElement.SelectSingleNode(key);
    Response.Write(mNode.Attributes["key"].Value.ToString());
    Response.Write("<br>");
    Response.Write(mNode.Attributes["value"].Value.ToString());
    这里关键的地方就是这个key了,
    key="//cccc[@key='edf']"
         ^^这里是从root开始逐层查找。如果需要定义从特定元素中查找
    需要这样定义
    key="/元素名称1/元素名称2[@属性名='属性值']"
    然后交给xmldocument来查找就ok了。
      

  4.   

    真是key的问题,我没有加两个斜杠。
    谢谢!