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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:18:02+00:00 2026-05-25T16:18:02+00:00

I am using HTML agility pack and parsing to an array. The information I

  • 0

I am using HTML agility pack and parsing to an array.

The information I am parsing changes and when it changes below a certain level I get unhandled exceptions because I am trying to bind the an element [][] that isn’t there.

How would I setup error checking to make sure if the array isn’t there it wouldn’t throw an Unhandled expection?

Eg… If I use the below code and there is no [2][1] then I get an exception, but the html changes so It needs to cope with null dor non existant arrays elements

    //first line
    textBlock1.Text = node[0][0];
    textBlock2.Text = node[0][1];
    textBlock3.Text = node[0][2];

    //first line
    textBlock4.Text = node[1][0];
    textBlock5.Text = node[1][1];
    textBlock6.Text = node[1][2];

    //first line
    textBlock7.Text = node[2][0];
    textBlock8.Text = node[2][1];
    textBlock9.Text = node[2][2];

Array is from this code:

void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    var html = e.Result;

    var doc = new HtmlDocument();
    doc.LoadHtml(html);

    var list = doc.DocumentNode.Descendants("div").ToList();

    var node = doc.DocumentNode.Descendants("table")
         .FirstOrDefault(x => x.Id == "departures")
        .Element("tbody")
         .Elements("tr")
          .Select(tr => tr.Elements("td").Select(td => td.InnerText).ToArray())
          .ToArray();
  • 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-05-25T16:18:03+00:00Added an answer on May 25, 2026 at 4:18 pm

    You can check length for both dimensions, e.g.

    if (node.Length > 2)
    {
       //first line
       if (node[2].Length > 0)
       {
          textBlock7.Text = node[2][0];
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using HTML Agility Pack to parse html content. I am using parsing
I am using html agility pack to parse html tabular information . Now there
I am parsing an html page using the Html Agility Pack . I am
I'm trying to get google search results using HTML Agility Pack, but I am
I want to parse the html table using html agility pack. I want to
I've looked for tutorials on using HTML Agility Pack as it seems to do
Using the HTML Agility Pack , how can I remove all HTML attributes, elements,
Why html agility pack is used to parse the information from the html file
I am trying to stop XSS attack so I am using html agility pack
i am using the HTML Agility pack to convert <font size=1>This is a test</font>

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.