Is there a wildcard to filter

Dec 26, 2009 at 12:49 PM

Hello
I like to capture the rows that contain a class with a text "no-match date-repetition"
The problem is that some contain the string "even expanded" and other "odd expanded" besides "no-match date repetition"

For Each node As HtmlAgilityPack.HtmlNode In document.DocumentNode.SelectNodes("//tr[@class='even expanded match no-date-repetition']")
            Response.Write(node.InnerHtml.ToString)
            Response.Write("</br>")
Next

Could I use this?

For Each node As HtmlAgilityPack.HtmlNode In document.DocumentNode.SelectNodes("//tr[@class='% match no-date-repetition']")
            Response.Write(node.InnerHtml.ToString)
            Response.Write("</br>")
Next

Thanks

Coordinator
Dec 27, 2009 at 10:29 AM

You should check .NET XPATH syntax as this is XPATH-related, not Html Agility Pack-related (as Html Agility Pack just reuses .NET XPATH implementation).

I don't think this is possible though... It's easier (but ok, less elegant...) to write an OR filter, like

//tr[@class='even expanded match no-date-repetition' or @class='odd expanded match no-date-repetition']

Mar 23, 2010 at 2:09 PM
elwilly wrote:

Could I use this?

For Each node As HtmlAgilityPack.HtmlNode In document.DocumentNode.SelectNodes("//tr[@class='% match no-date-repetition']")
            Response.Write(node.InnerHtml.ToString)
            Response.Write("</br>")
Next

I know it's an old issue. But i thought for future references someone might stumble upon this as i did myself when trying to find a solution to a similair problem...

 

XPath has a contains-functions as well as a starts-with that is useful in scenarios like these...

So instead of the above this should yield the wanted result

For Each node As HtmlAgilityPack.HtmlNode In document.DocumentNode.SelectNodes("//tr[contains(@class,'match no-date-repetition']")
            Response.Write(node.InnerHtml.ToString)
            Response.Write("</br>")
Next

Jan 29, 2013 at 5:58 AM

Hi Trappski,

 

Can you help me with match() of HTMLAgility.

How to handle the case sensitivity?

 

Eg: If i want to select both "div" & "DIV" node how one can do this?

Jan 29, 2013 at 11:44 AM

I have tried this piece of code and it returns both div tags so it's not case sensative.

            HtmlDocument hp = new HtmlDocument();
            hp.LoadHtml("<form>
Hello
Me 2
</form>"
); var nodes = hp.DocumentNode.SelectNodes("//div");

Is this all you were looking for? A case insensitive tag search?

Jan 30, 2013 at 3:47 AM
Edited Jan 30, 2013 at 3:49 AM

Hi LeeJeary,

Thank you for replying but the same piece of code giving a case sensitive behavior to me.

            HtmlDocument hp = new HtmlDocument();
            hp.LoadHtml("<form><div><DIV>sdf</DIV></div>HelloMe 2</form>");

            var small = hp.DocumentNode.SelectNodes("//div");
           var caps= hp.DocumentNode.SelectNodes("//DIV");	
 
small.Count=1
caps.Count=1
Jan 30, 2013 at 4:54 AM

Very unusual 

mine has

small.Count == 2

caps == null;

What version of the dll are you using? I'm using the version from NuGet 1.4.6.

tested with different .net frameworks 3.5-4.5 and all work.

Jan 30, 2013 at 4:59 AM
Edited Jan 30, 2013 at 5:37 AM

You could try this option

 

            AP.HtmlDocument hp = new AP.HtmlDocument();
            hp.LoadHtml("<form><div>HelloMe 2</div><DIV>sdf</DIV></form>");

            var small = hp.DocumentNode.SelectNodes("//div | //DIV");
            var caps = hp.DocumentNode.SelectNodes("//DIV");

I replaced the upper case tag DIV with img and it worked.

 

small.Count == 2

caps.Count == 1

Jan 30, 2013 at 5:29 AM

I have downloaded from the following :

http://htmlagilitypack.codeplex.com/releases/view/90925

Jan 30, 2013 at 5:45 AM
arsh wrote:

I have downloaded from the following :

http://htmlagilitypack.codeplex.com/releases/view/90925

I downloaded the same version tried it on version .Net 2.0 and .Net 4.0. Visual studio version 2010 and 2012 and still getting the same results where small.Count is 2 and caps is null.

Sorry not much more help as cant reproduce the issue.. :-/ 

Jan 30, 2013 at 5:58 AM
Edited Jan 30, 2013 at 6:26 AM

Well Thanks  Lee for your help :-) 

 

just for your reference following is my code :


 HtmlDocument NewXmlDoc = new HtmlDocument(); 

string xmlFile ="Path';

NewXmlDoc.Load(xmlFile + "Test.html");

 HtmlNodeCollection ConditionalList = null;

  ConditionalList = NewXmlDoc.DocumentNode.SelectNodes("//div");

 

and xml file looks like the below:

<TextFlow fontFamily="Arial"> 

 

<div>This is in smal</div>

<DIV>This is in Caps</DIV>

 

</TextFlow>

Jan 30, 2013 at 11:03 AM

 

Hi LeeJeary,

  problem was the version i guess ., it was 1.4.0 ! can you check it once.

 

Well now I have switch to 1.4.6 and it worked :-)

 

Anyways thanks for looking into it.

 

Regards,

Salma

Jan 30, 2013 at 12:08 PM

Perfect.. Glad it's working..

Lee

On Jan 30, 2013 11:04 PM, "arsh" <notifications@codeplex.com> wrote:

From: arsh

Hi LeeJeary,

problem was the version i guess ., it was 1.4.0 ! can you check it once.

Well now I have switch to 1.4.6 and it worked :-)

Anyways thanks for looking into it.

Regards,

Salma

Read the full discussion online.

To add a post to this discussion, reply to this email (htmlagilitypack@discussions.codeplex.com)

To start a new discussion for this project, email htmlagilitypack@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com