Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SelectNodes with XPath ignoring cases

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

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.

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>

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

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

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

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

Any idea?

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

like image 943
vfportero Avatar asked Mar 21 '12 12:03

vfportero


People also ask

Is Selectsinglenode case sensitive?

For eg. If you have Abc in xml or ABC or abc, we are converting it to abc then comparing. Now what if your variable has upper case and lower case combination or all uppercase? Then we will convert your variable too to lower case.


1 Answers

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.

like image 107
JWiley Avatar answered Sep 28 '22 21:09

JWiley