我有一个HtmlElementCollection,我想使用Linq从另一个列表中获得id包含id的HtmlElements列表。
所以我试了几件事,但都没成功。我从集合中得到一个列表,并尝试过滤它。
这是部分ids的列表。元素ids是不同的,它们有与这个列表相对应的ids,加上一些开头看起来随机的数字。
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"};元素ids如下所示:
"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",所以我把我的收藏放在一个列表中,我可以查询。
var elems = doc.All.Cast<HtmlElement>();我尝试过不同的方法,但没有一种方法很有效。我也想使用Linq,并避免一个丑陋的2-DForeach循环。
有什么想法吗?
发布于 2014-02-13 18:48:33
所以有点像elems.Where(x => ids.Any(id => x.ID.Contains(id)))
这样做的目的是遍历elems中的每个项( html元素列表),然后遍历id集合中的每个id,如果匹配,则返回该元素。
https://stackoverflow.com/questions/21762879
复制相似问题