Find nodes in HtmlNodeCollection

Posted on 2013-01-04
Last Modified: 2013-01-04
Hello EE,

I have in my project HtmlUtilityPack import.

Im trying to find a Div and the result I insert in a HtmlNodeCollection like this :

        Dim nodes As HtmlNodeCollection = doc.DocumentNode.SelectNodes("//div[@id='myID']")

Open in new window

but inside this DIV there are many <a href='' title='hello'></a>

I want all the title attribute of al of them. but only in that specific div..

im not sure where to go with this... should be soemthing like :

Dim list as new List(of string)
For Each node As HtmlNode In nodes

can you help ?
Question by:PhilippeRenaud
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 75

Accepted Solution

käµfm³d   👽 earned 500 total points
ID: 38745344
Do you mean HTML Agility Pack? If so, you can set up your XPath to select that attribute for you.


Dim nodes As HtmlNodeCollection = doc.DocumentNode.SelectNodes("//div[@id='myID']//a/@title")

Open in new window

Then you could just iterate over that result set:

Dim list as new List(of string)

For Each node As HtmlNode In nodes

Open in new window


Author Comment

ID: 38745736
yes sorry agility.

but it cant be done on 2 lines? i need to do it on doc.DocumentNode?

i cannot do it on the nodes variable to reach @a?

because otherwise i always need to re-iterate on doc variable and sometimes there is tons of source code lines, but still maybe its fast also.. i dont know
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38745819
I'm probably not understanding what you are asking, but if you would like to stick with the logic you currently have, then it should be along the lines of:

For Each node As HtmlNode In nodes

Open in new window


Author Closing Comment

ID: 38746076
Thank you

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question