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
  • 2
  • 2
LVL 74

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 74

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now