XPath忽略大小写的SelectNodes [英] SelectNodes with XPath ignoring cases

查看:175
本文介绍了XPath忽略大小写的SelectNodes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在查找包含某些字符串而忽略字符大小写的XPath中的元素时遇到问题。

I have a problem finding elements in XPath that's contains a certain string ignoring character casing.

我想在HTML页面中查找所有ID为id的节点文本页脚忽略大小写。

I want to find in a HTML page all the nodes with id contains the text "footer" ignoring it's write in uppercase or lowercase.

在我的示例中,我有一个不同的html文本,如下:

In my example I have a different html text like this:

<div id="footer">some text</div>
<div id="anotherfooter">some text</div>
<div id="AnotherFooter">some text</div>
<div id="AnotherFooterAgain">some text</div>

我需要选择所有节点(或者在任何情况下都选择 footer一词的组合

I need to select all nodes (or any combination in any case with the word "footer" in the id) with a XPath.

当前我正在使用此xpath,但不适用于UpperCase id

Currently I'm using this xpath but doesn't work for the UpperCase id's

"//*[contains(./@id, 'footer')]/@id"

我已经完成了translate()的多个测试,但是没有按预期工作。

I've done several tests with translate() but doesn't work as I expected.

有什么想法吗?

编辑:我正在将HtmlAgilityPack与XPath 1.0版本配合使用。

I'm using HtmlAgilityPack with works with the XPath 1.0 version.

推荐答案

不确定您是否尝试过此操作,但这是我针对区分大小写的内容所做的搜索:

Not sure if you've tried this yet, but this is what I do for case sensitive contains searches:

//*[contains(translate(./@id,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), 'footer')]/@id

我看到您已经找到了解决方案,所以我会发布此答案,以防其他人遇到相同的问题。

I saw you have found your solution, so I'm posting this answer in case others have the same issue.

这篇关于XPath忽略大小写的SelectNodes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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