Pattern Matching?

Topics: User Forum
Nov 7, 2007 at 4:09 AM
Is it possible to do pattern matching? The page I'm extracting data from has:

<tr class="row1">
<td>some text</td>
<tr class="row0">
<td>some more text</td>

I'm trying to match just on row whether it's 0 or 1 but I can't seem to find a way to use a variable to do something like:

HtmlNodeCollection row1 = table0.SelectNodes("//tr@class='row/*'");
where the "/*" is a wild card to match anything after row

I think if I can use pattern matching I can select nodes that contain the class row regardless of it having class=row1 or class=row0

Nov 17, 2007 at 4:53 PM
Welcome to XPATH :-)
SelectNodes("//trstarts-with(@class, 'row)]);
should do the trick

If you want smarter XPATH pattern matching, you should have a look to EXSLT.NET (
Nov 23, 2007 at 10:27 PM
I keep getting this error:
Message: "'//*matches(@class,'free')' has an invalid token."

when i do the following:

Goal: I want to look into the entire dom for class name that has 'free' in the name.

I also ventured into 'contains' with no luck.

Any help would be greatly appreciated.

Thanks a lot
Murali Bala
Dec 5, 2007 at 7:33 PM
Edited Dec 5, 2007 at 7:44 PM
A small corrrection to the code of simonm:

SelectNodes("//tr[starts-with(@class, 'row')]);
Dec 27, 2007 at 11:14 PM
To add to bsd12673's question
I have a scenarios and I wanted to see if HTMLAgilityPack is useful in solving this problem scenario, if yes is there a sample code to look at

Scenario : On a webportal that sells products it has a page where search results are displayed listing all the products matching the criteria. No matter what the criteria is, the products are displayed in the same style on the UI. Is it possible to extract partial data from the rendered html, like I only want to extract product name, product sku number and may be description.

I am new to and C# if you can help me with a small sample of code it would be really helpful.

I appreciate your efforts.