日期:2014-05-20  浏览次数:20352 次

求一个 xpath 语法!!!!
<root>
    <room   id= "0 ">
          <say   id= "5 ">
                <test> aaa <test>
          </say>
          <say   id= "6 ">
                <test> bbb <test>
          </say>
          <say   id= "7 ">
                <test> bbb <test>
          </say>
              ......
    </room>
  <room   id= "1 ">
   
    </room>
</root>

返回所有room节点id属性等于0   的里面的say子节点id属性大于5的   并且test值等于666的所有say节点

回答正确立刻给分

------解决方案--------------------
string str = @ " <root> <room id= " "0 " "> <say id= " "5 " "> <test> aaa </test> </say> <say id= " "6 " "> <test> 666 </test> </say> <say id= " "7 " "> <test> 666 </test> </say> </room> <room id= " "1 " "> </room> </root> "; XmlDocument dom = new XmlDocument(); dom.LoadXml(str); XmlNodeList nl = dom.SelectNodes( "//room[@id= '0 ']/say[@id> '5 '][./test[.= '666 ']] "); for (int i = 0; i < nl.Count; i++) { Response.Write(nl[i].Name + ", "+ nl[i].Attributes[ "id "].Value+ " <BR> "); }