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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:37:43+00:00 2026-05-25T14:37:43+00:00

I am parsing HTML to an array using the following code. void client_DownloadStringCompleted(object sender,

  • 0

I am parsing HTML to an array using the following 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(); 

I am then outputing to Texblock with the below code.

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

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

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

My issue is this: The HTMl changes through the day, so some times there isn’t and [2] and sometimes there is up to [12].

What I would like to know is how can I wite a conditional statment to check if the array exists and only output if it has a value.

I have tried a conditional statement like below, but it still shows a Unhandled exception when there aren’t any node[2] or node[1] results

if (node[2][0].length > 0)
   {
       textBlock1.Text = node[2][0];
    }

Any help will be apprecaited. If you need clarification on this please let me know.

  • 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-25T14:37:44+00:00Added an answer on May 25, 2026 at 2:37 pm

    To avoid the invalid index, all the dimensions must be ensured, e.g.

    if (node.length > 2 && node[2].length > 0) {
        // Okay to use node[2][0]
        // Since && is short-circuiting it will never make second
        // check if first fails.
    }
    

    To me, a more fundamental issue seems to be that the text boxes are not variadic but are fixed (box1, box2, etc). Consider using a different control instead, perhaps a list control of sorts. Then n items can be added uniformly (and just using a loop construct without need for the first index check). Text boxes can also be dynamically created, but this would not be my first choice.

    Happy coding.

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

Sidebar

Related Questions

I'm new to F# and functional and am working on some HTML parsing code.
I am trying to learn using DOMDocument for parsing HTML code. I am just
I am using HTML agility pack and parsing to an array. The information I
I'm new to DOM parsing in PHP: I have a HTML file that I'm
I'm parsing out an HTML table and building an array based on the row
Parsing HTML / JS codes to get info using PHP. www.asos.com/Asos/Little-Asos-Union-Jack-T-Shirt/Prod/pgeproduct.aspx?iid=1273626 Take a look
I am creating my own object: gridObject = new Object(); I am then using
I am parsing html tabular information with the help of the html agility pack
I have a console application which is parsing HTML documents via the WebRequest method
I am parsing some HTML source. Is there a regex script to find out

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.