基于过滤部分ID的列表上HTML元素的列表 [英] Filtering a list of HtmlElements based on a list of partial ids

查看:111
本文介绍了基于过滤部分ID的列表上HTML元素的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HtmlElementCollection,我想使用LINQ获得HTML元素的ID中包含从另一个列表中的ID列表。

I've got an HtmlElementCollection and I want to use Linq to get a list of HtmlElements whose ids contain an id from another list.

所以,我已经试过几件事情没有一个制定。我从收藏列表,并试图对其进行过滤。

So I've tried a couple of things none of which worked out. I get a list from the collection and try to filter it.

这是部分ID列表。该元素的id是不同的,他们有对应到这个列表加的开头有一些随机似乎数字标识。

This is the list of partial ids. The element ids are distinct, and they have ids that correspond to this list plus some random-seeming numbers at the beginning.

string[] ids = {"btadminh_struct.description",
"thtmlb_textView_6",
"thtmlb_textView_7",
"btadminh_struct.object_id",
"thtmlb_textView_12",
"zbtsalesset_struct.po_number_sold",
"thtmlb_textView_17",
"thtmlb_textView_21",
"thtmlb_textView_24",
"btcustomerh_z_followupdate",
"thtmlb_textView_29",
"btrefobjmain_ibibase",
"btrefobjmain_ibinstancedesc",
"btpartnerserviceto_struct.description_name",
"btpartnerset_contact_name",
"zzericempresp_struct.partner_no",
"zbtcsrowner_struct.partner_no",
"btcustomerh_struct.zcomments",
"thtmlb_textView_19",
"btadminh_servicecontractdescr",
"btcustomerh_zcontracttype_descr",
"btrefobjmain_network_id",
"btrefobjmain_node_id",
"btrefobjmain_site_id"};

元素的ID是这样的:

"C29_W87_V88_btrefobjmain_network_instance",
"C29_W87_V88_btrefobjmain_network_id__items",
"C29_W87_V88_btrefobjmain_network_id",
"C29_W87_V88_btrefobjmain_network_id-btn",
"C29_W87_V88_btrefobjmain_network_id__key",
"C29_W87_V88_thtmlb_label_2",
"C29_W87_V88_btrefobjmain_service_id__items",
"C29_W87_V88_btrefobjmain_service_id",
"C29_W87_V88_btrefobjmain_service_id-btn",
"C29_W87_V88_btrefobjmain_service_id__key",
"C29_W87_V88_thtmlb_label_3",
"C29_W87_V88_btrefobjmain_networkadap_id__items",
"C29_W87_V88_btrefobjmain_networkadap_id",
"C29_W87_V88_btrefobjmain_networkadap_id-btn",
"C29_W87_V88_btrefobjmain_networkadap_id__key",

所以我把我收集到我可以查询列表。

So I've put my collection into a List that I can query.

var elems = doc.All.Cast<HtmlElement>();



我尝试过不同的方法,其中没有一个是相当的工作。我也想使用LINQ和避免一个丑陋的2-D foreach循环。

I've tried different approaches, none of which are quite working. I'd also like to use Linq and avoid an ugly 2-D foreach loop.

任何想法?

推荐答案

所以像 elems.Where(X => ids.Any(ID => x.ID.Contains(ID)))

这是什么做的是通过每个项目要在elems(你的HTML元素列表),然后在你的ID收集,如果任何比赛通过每个ID去,那么它将返回该元素。

What this is doing is going through each item in elems (your html element list) and then going through each id in your id collection and if any match, then it will return that element.

这篇关于基于过滤部分ID的列表上HTML元素的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆