XPath忽略大小写的SelectNodes

编程入门 行业动态 更新时间:2024-10-09 17:29:11
本文介绍了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

本文发布于:2023-11-11 08:27:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577881.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小写   XPath   SelectNodes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!