当前位置: 代码迷 >> ASP.NET >> 请问xpath怎么写
  详细解决方案

请问xpath怎么写

热度:4869   发布时间:2013-02-26 00:00:00.0
请教xpath如何写
XML code
<class>  <student>    <no>1</no>    <name>Ann</name>    <sex>female</sex>    <age>15</age>    <score>90</score>  </student>  <student>    <no>2</no>    <name>Bob</name>    <sex>male</sex>    <age>16</age>    <score>80</score>  </student>  <student>    ……  </student>  <student>    ……  </student></class>
 
想获得score>90分学生信息(只要no、name、score),xpath应该怎么写啊?

------解决方案--------------------------------------------------------
C# code
        string strXml = @"<class>  <student>    <no>1</no>    <name>Ann</name>    <sex>female</sex>    <age>15</age>    <score>90</score>  </student>  <student>    <no>2</no>    <name>Bob</name>    <sex>male</sex>    <age>16</age>    <score>80</score>  </student>  <student>    <no>3</no>    <name>ttt</name>    <sex>j</sex>    <age>15</age>    <score>92</score>  </student>  <student>     </student></class>";        XmlDocument xdoc = new XmlDocument();        xdoc.LoadXml(strXml);        string strXPath = string.Empty;        strXPath = "/class/student[score>=90]";        XmlNodeList oXmlNodes = xdoc.SelectNodes(strXPath);        foreach (XmlNode node in oXmlNodes)        {            string strName = node.SelectSingleNode("/class/student/name").InnerText ;        }
------解决方案--------------------------------------------------------
应该是不可以的。就像冰箱里有N多瓶饮料,你能否不开冰箱就喝到其中的一瓶呢。