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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:15:51+00:00 2026-05-30T13:15:51+00:00

From this XHTML source: <div class = page> <h1>UNIQUE NAME</h1> <table> <tbody> <tr> <td>DATA

  • 0

From this XHTML source:

<div class = "page">  
<h1>UNIQUE NAME</h1>
  <table>
    <tbody>
      <tr>
        <td>DATA TO EXTRACT 1</td>
      </tr>
      <tr>
        <td />
        <td />
        <td />
        <td />
        <td />
        <td>DATA TO EXTRACT 2</td>
      </tr>
    </tbody>
 </table>
 etc...

There are multiple instances of UNIQUE NAME with a similar set of child elements.

I need to locate the UNIQUE NAME element and extract all values (DATA TO EXTRACT) within each of the child element tags. In addition, I need to keep a count of where each value is located. For example DATA TO EXTRACT 1 would be at tr 1, td 1. DATA TO EXTRACT 2 would be at tr 2, td 6.

I am new to linq to xml and I was wondering whether someone could point me in the right direction with regards to a strategy. I have managed to figure out how to get to the UNIQUE name element with the following code:

var choice1 = (from category in _data.Descendants("div")
                       where category.Element("h1").Value == "UNIQUE NAME"
                       select category).DescendantNodes();

This returns a set of the values, which I’m sure I could loop through but I’m sure there must be a more elegant way of achieving this goal.

Many thanks!

  • 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-30T13:15:53+00:00Added an answer on May 30, 2026 at 1:15 pm

    Here’s one way of doing it using LINQ:

    var choice1 =
        from category in _data.Descendants("div")
        where category.Element("h1").Value == "UNIQUE NAME"
        from row in category.Descendants("tr").Select((element, index) => new { element, index })
        from col in row.element.Elements("td").Select((element, index) => new { element, index })
        where !string.IsNullOrEmpty(col.element.Value)
        select new
        {
            RowIndex = row.index + 1,   // one-based index
            ColIndex = col.index + 1,
            Value = col.element.Value,
        };
    

    An example of how to use your results:

    foreach (var v in choice1)
        Console.WriteLine(string.Format(
            "RowIndex = {0}, ColIndex = {1}, Value = \"{2}\".",
            v.RowIndex, v.ColIndex, v.Value));
    

    …which would output:

    RowIndex = 1, ColIndex = 1, Value = "DATA TO EXTRACT 1".
    RowIndex = 2, ColIndex = 6, Value = "DATA TO EXTRACT 2".
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from this (normal dataGrid) (source: narod.ru ) into this (horisontal data grid) How to
From browsing on this site and elsewhere, I've learned that serving websites as XHTML
From this page: http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models#dealing-with-relations:creating-related-records You can see that it says $obj['property']; is the recommended
I'm using SimpleXML to parse a data file from an external source. I'm trying
I am using a master page... Then there is an .aspx that uses this
I'm using jQuery 1.5.2 trying to dynamically load a div from one source into
I am currently using this script to get new data every second from record_count.php
I'm trying to populate a div in html via ajax. The data source is
From this post . One obvious problem is scalability/performance. What are the other problems
From this question , a neat answer about using COALESCE to simplify complex logic

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.