Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7956103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:53:42+00:00 2026-06-04T03:53:42+00:00

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(content); var nodes = doc.DocumentNode.SelectNodes(//div[@class=\noprint res\]/div); if (nodes !=

  • 0
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(content);

var nodes = doc.DocumentNode.SelectNodes("//div[@class=\"noprint res\"]/div");
if (nodes != null)
{
    foreach (HtmlNode data in nodes)
    {
                  // Works but not what I want
                  MessageBox.Show(data.InnerHtml);

                  // Should work ? but does not ?
                  MessageBox.Show(data.SelectSingleNode("//span[@class=\"pp-place-title\"]").InnerText);
    }
}

I am trying to parse the results of a HTML, the initial node for the foreach, works just as expected and gives me a result of 10 items which matchs what I need.

When I get into the foreach, if I output the inner html of the data item it display the correct data but if I output the SelectSingleNode it will always display the data from the first item from the foreach, is that a normal behavior or am I doing something wrong ?

In order to resolve the issue I had to create a new html inside the foreach for every data item like this:

HtmlAgilityPack.HtmlDocument innerDoc = new HtmlAgilityPack.HtmlDocument();
innerDoc.LoadHtml(data.InnerHtml);

// Select what I need
MessageBox.Show(innerDoc.DocumentNode.SelectSingleNode("//span[@class=\"pp-place-title\"]").InnerText);

Then I get the correct per item data.

The page I was trying to get data from was http://maps.google.com/maps?q=consulting+loc:+US if u want to try and see what happens for yourself.

Basically I am reading the left side column for company names and the above happens.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:53:43+00:00Added an answer on June 4, 2026 at 3:53 am

    By starting your XPath expression with //, you’re searching in the entire document that contains the data node.

    You should be able to use ".//[...]" to only check nodes within data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using HtmlAgilityPack. I create an HtmlDocument and LoadHtml with the following string:
The example on codeplex is this : HtmlDocument doc = new HtmlDocument(); doc.Load(file.htm); foreach(HtmlNode
WebClient GodLikeClient = new WebClient(); HtmlAgilityPack.HtmlDocument GodLikeHTML = new HtmlAgilityPack.HtmlDocument(); GodLikeHTML.Load(GodLikeClient.OpenRead(www.alfa.lt); So this code
I am using HtmlAgilityPack to parse my html doc, but I can't get the
<html> <body> <div class=main> <div class=submain><h2></h2><p></p><ul></ul> </div> <div class=submain><h2></h2><p></p><ul></ul> </div> </div> </body> </html> I
Does HtmlAgilityPack have the ability to return the whole HTML markup from an HtmlDocument
I'm using HtmlAgilityPack how can I get the domain from the following objects? private
I am using HTMLAgilityPack in my application, and i want to get the item(node)
I've been using the HtmlAgilityPack to eat some XHTML documents, however, if I want
I am parsing an XML API response with HTMLAgilityPack. I am able to select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.