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 7750461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:17:54+00:00 2026-06-01T11:17:54+00:00

I’ve been working for a while with a node set in C#/ html agility

  • 0

I’ve been working for a while with a node set in C#/ html agility pack, and through trial and error I have a a list of nodes that I want to loop over, getting the child nodes of each of the nodes from the loop. I’d like to refer to them by index # (seems to be the easiest, yet here I post). I’ve tried different ways to format the xpath, including “[0]”, “/[0]”, “tr/[0]”, etc. Here’s what I have so far, everything working fine up to the first commented line:

protected override List<IDataPoint> ReturnDataPointsFromIndividualAddressString(string AddressString)
            {
                List<IDataPoint> earningsAnnouncements = new List<IDataPoint>();

                HtmlWeb hwObject = new HtmlWeb();
                HtmlDocument htmlDoc = hwObject.Load(AddressString);

                if (htmlDoc.DocumentNode != null)
                {
                    List<HtmlNode> nodeList = new List<HtmlNode>();

                    var nodes = htmlDoc.DocumentNode.SelectNodes("html[1]/body[1]/table[4]/tr[1]/td[1]/table[1]/tr");

                    if (nodes != null)
                    {
                        foreach (HtmlNode n in nodes)
                        {
                            if (n.OuterHtml.Contains("finance.yahoo.com"))
                                    nodeList.Add(n);
                        }
                    }

                    foreach (HtmlNode node in nodeList)
                    {
                        EarningsAnnouncementDP earningsAnnouncement = new EarningsAnnouncementDP();

                        //Error: Expression must evaluate to a node set.
                        earningsAnnouncement.Company = (node.SelectSingleNode("[0]")).InnerText.ToString();
                        earningsAnnouncement.Ticker = node.SelectSingleNode("[1]").InnerText.ToString();
                        earningsAnnouncement.Estimate = node.SelectSingleNode("[2]").InnerText.ToString();
                        earningsAnnouncement.AnnouncementTime = node.SelectSingleNode("[3]").InnerText.ToString();

                        earningsAnnouncements.Add(earningsAnnouncement);
                    }

                    return earningsAnnouncements;
                }
  • 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-01T11:17:55+00:00Added an answer on June 1, 2026 at 11:17 am

    You have traversed till tr node. Now you should access td node. So you can use the XPATH like below.

    node.SelectSingleNode("./td[1]").InnerText;
    node.SelectSingleNode("td[1]").InnerText;
    

    Also the first td node is accessed as td[1] and not td[0].

    As Alex pointed out you can write something like below which is an excellent suggestion.

    node.ChildNodes[0].InnerText
    

    HTH

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.