/*查找XML*/
var filePath = Server.MapPath("~/xml/sample.xml");
XDocument doc = XDocument.Load(filePath);
var text1 = doc.Descendants("用户")  //定位到节点 
                .Where(p => p.Element("性别").Value.Contains('')) //若要筛选就用上这个语句 
                .Select(p => new { name = p.Element("姓名").Value });
foreach (var a in text1)
{
    str += a.name + "<br/>";
}

/*结果*/
张三
李四
<?xml version="1.0" encoding="gb2312" standalone="yes"?>
<班级信息>
  <用户>
    <姓名>张三</姓名>
    <性别></性别>
  </用户>
  <用户>
    <姓名>李四</姓名>
    <性别></性别>
  </用户>
  <用户>
    <姓名>王琳</姓名>
    <性别></性别>
  </用户>
</班级信息>

 

相关文章:

  • 2021-09-02
  • 2021-06-02
  • 2022-01-14
  • 2021-07-11
  • 2021-10-12
  • 2021-12-16
  • 2021-10-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案