Thành Trần
Thành Trần

Reputation: 1

c# SelectNodes with XPath ignoring cases in content of tag HTML

i have a problem with my project. i got HTML from a website,then i want to SelectSingleNode with xpath, this is content html:

<html>
<body>
<div>
<h3 class="bp">Groups you are in</h3>
</div> </body> </html>

and this is my code:

var xpath = string.Format("//html/body/div/h3[.= '{0}'","groups you are in")
var header = BuildDom("{this is link website i get html}").SelectSingleNode(xpath);

this is my class BuildDom:

HtmlNode BuildDom(string url)
{
    string htmlContent = _http.DownloadContent(url);
    return HtmlHelper.BuildDom(htmlContent);
}

plz look at:

var header = BuildDom("{this is link website i get html}").SelectSingleNode(xpath);

header will be null; because in html tag h3: Groups you are in

and in my xpath: "groups you are in"

how can i use with xpath "group you are in"? ignoring cases in tag h3 from html. i cant change my xpath to "Groups you are in" because in html, sometimes h3 content "groups you are in", sometimes content "Groups you are in", or "Group You Are In"

Upvotes: 0

Views: 105

Answers (2)

take
take

Reputation: 2222

One solution is, that you match against lower, or upper case.

"//html/body/div/h3[lower-case(.) = 'groups you are in']"

Upvotes: 0

Andersson
Andersson

Reputation: 52685

You can try to use matches(). Flag "i" allow to ignore cases

//html/body/div/h3[matches(., "groups you are in", "i")]

Upvotes: 1

Related Questions