linq To xml 查询问题

yuandinxiaozhu 2013-01-29 05:00:28
我现在要查找出一个xml元素中具有特定子元素的类似值。可能这样说不好理解。下面贴段代码解释一下:
var query = from ele in xElement.Elements("Device")
where ele.Element("DeviceName").Value == "VD1"
select ele;
这段代码查找出DeviceName元素值为VD1的xml。得到的结果是:
<Device>
<DeviceName>VD1</DeviceName>
</Device>
可是。DeviceName的值有VD1,VD2,VD3等等,我所要实现的是把所有VD都找出来。就好像sql的like 'VD%'一样。这个要怎么实现。
谢谢!!
...全文
2062 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2013-06-03
  • 打赏
  • 举报
回复
var query = from ele in xElement.Elements("Device") where ele.Element("DeviceName").Value.Contains("VD") select ele; 确实要搞清楚以下3者的区别所在 StartsWith EndsWith Contains
完美算法 2013-05-31
  • 打赏
  • 举报
回复
引用 14 楼 fcdesk 的回复:
Value.Contains
还包括了1VD,2VD......
完美算法 2013-05-31
  • 打赏
  • 举报
回复
Value.Contains
星空蔚蓝 2013-03-21
  • 打赏
  • 举报
回复
引用 2 楼 yuandinxiaozhu 的回复:
刚发完就写出来了。应该这样写: var query = from ele in xElement.Elements("Device") where ele.Element("DeviceName").Value.Contains("VD") sele……
正解啊
jo5690 2013-03-18
  • 打赏
  • 举报
回复
我也要分
y3709180 2013-03-15
  • 打赏
  • 举报
回复
Contains() 就可以进行模糊查询
a12345_asdfg 2013-03-12
  • 打赏
  • 举报
回复
接分
lanymy 2013-03-12
  • 打赏
  • 举报
回复
where ele.Element("DeviceName").Value.Contains("VD") 都写出来了 直接用这个就完事了
完美算法 2013-02-02
  • 打赏
  • 举报
回复

var query = from ele in xElement.Elements("Device")
      where ele.Element("DeviceName").Value.StartsWith("VD")
      select ele;
完美算法 2013-02-02
  • 打赏
  • 举报
回复

var query = from ele in xElement.Elements("Device")
     where ele.Element("DeviceName").Value.StartsWith("VD1")
     select ele;
q107770540 2013-01-29
  • 打赏
  • 举报
回复
注意这三者的区别 startwith endwith contains
newtee 2013-01-29
  • 打赏
  • 举报
回复
刚想回复contains方法 看见2楼算了 楼主是不是没有看过专门讲解的LINQ的书啊?
  • 打赏
  • 举报
回复
遍历,StartsWith("VD")
yuandinxiaozhu 2013-01-29
  • 打赏
  • 举报
回复
引用 1 楼 bdmh 的回复:
where 条件1 | 条件2 | 条件3
错了,VD1,VD2....等等,是不可能知道到底有多少个VD的,所以不可能条件1 | 条件2 | 条件3。我已经做出来了。一样送分给你
yuandinxiaozhu 2013-01-29
  • 打赏
  • 举报
回复
刚发完就写出来了。应该这样写: var query = from ele in xElement.Elements("Device") where ele.Element("DeviceName").Value.Contains("VD") select ele; 下面回复的直接送分=。=
bdmh 2013-01-29
  • 打赏
  • 举报
回复
where 条件1 | 条件2 | 条件3

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧