How to use SelectSingleNode

Topics: Developer Forum, Project Management Forum, User Forum
Jul 31, 2009 at 10:43 PM

Hi,

I am trying to use "SelectSingleNode", but i am still having a problem. Plese see my code below for example.

 

HtmlNodeCollection tableCol = docNew.DocumentNode.SelectNodes("//tbody[@class='result']//tr");
                foreach (HtmlNode tableNode in tableCol)
                {
                    HtmlNode sellInfo = tableNode.SelectSingleNode("ul[@class='sellerInformation']");
                    HtmlNode sellPrice = sellInfo.SelectSingleNode("div[@class='seller']//b");
                }

 

    HtmlNodeCollection tableCol = docNew.DocumentNode.SelectNodes("//tbody[@class='result']//tr");

 foreach (HtmlNode tableNode in tableCol)

                {

                    HtmlNode Info = tableNode.SelectSingleNode("ul[@class='Information']");

                }

 

each time that the code loop thrugh "tableCol" Why the "Info" always returns only first ChildNodes? 

Any experts please advise,

Thanks,

Aug 2, 2009 at 11:50 AM

Hi

So you are looking for an UL-element inside TR-elements? Usually such elements are within TD-elements. You are sure that the UL is a child of a TR and not a TD? Did you mean:

SelectSingleNode("td/ul[@class='Information']");

Also, it is important to know what Info.Name is, so you can compare it to the actual (X)HTML you are reading from, so you may see where the error lies.

Aug 3, 2009 at 5:30 PM

Thank you so much CoolSpin. It works now. :)