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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:00:54+00:00 2026-06-03T12:00:54+00:00

I am using Web-Harvest to do some web page scraping. I have a table

  • 0

I am using Web-Harvest to do some web page “scraping”. I have a table of values that I need to organize. The table is very simple. However, I need to use the table’s column headings to determine the data types for each column. The table looks something like this….

<table>
  <tr class="header">
    <td>Name</td>
    <td>Age</td>
    <td>Gender</td>
  </tr>
  <tr>
    <td>Bill</td>
    <td>25</td>
    <td>M</td>
  </tr>
  <tr>
    <td>Emily</td>
    <td>31</td>
    <td>F</td>
  </tr>
</table>

I’m using XQuery, as shown in the Web-Harvest examples, and I know how to get the values by index and also using attributes (class, id, etc.) but in this case, I’m not sure how to determine that column 1 is name, column 2 is age, etc… I want to output XML in this form…

<person>
  <name>Bill</name>
  <age>25</age>
  <gender>M</gender>
</person>
<person>
  <name>Emily</name>
  <age>31</age>
  <gender>F</gender>
</person>

I saw this code fragment from another post but I am not exactly sure how it works.

//tr[td[.="Jim"]]/td[count(ancestor::table/thead/tr/th[.="Credit"]/preceding-sibling::*)+1]

It looks like for each row the ancestor (parent?) is referenced to find the corresponding column heading. Other than that, I’m lost. Any additional information would be very helpful.

Thanks in advance.

  • 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-03T12:00:55+00:00Added an answer on June 3, 2026 at 12:00 pm

    This XQuery expression:

      <persons>
       {
       let $names := /*/tr[1]/td
         return
             for $tr in /*/tr[position() ge 2]
               return
                 <person>
                   { for $i in 1 to count($tr/td)
                       return
                         element {$names[$i]} {$tr/td[$i]}
                   }
                </person>
         }
       </persons>     
    

    when applied on the provided XML document:

    <table>
      <tr class="header">
        <td>Name</td>
        <td>Age</td>
        <td>Gender</td>
      </tr>
      <tr>
        <td>Bill</td>
        <td>25</td>
        <td>M</td>
      </tr>
      <tr>
        <td>Emily</td>
        <td>31</td>
        <td>F</td>
      </tr>
    </table>
    

    produces the wanted, correct result:

    <persons>
       <person>
          <Name>
             <td>Bill</td>
          </Name>
          <Age>
             <td>25</td>
          </Age>
          <Gender>
             <td>M</td>
          </Gender>
       </person>
       <person>
          <Name>
             <td>Emily</td>
          </Name>
          <Age>
             <td>31</td>
          </Age>
          <Gender>
             <td>F</td>
          </Gender>
       </person>
    </persons>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using web forms I know that you can only have one ASP.NET form on
we are using web-ehcache's net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter, that configured by xml, to cache page where is
I have a current build using teambuild/msbuild that I need to integrate a wix
I'm using Web-Harvest to extract some data from a site. Site gets a POST
Currently we're using Web Application project, so we have a gain with compilation. But
I am using web client class to HTML data from a web page. Now
I am using Web SQL for my app that I intend to run on
I like to get inspiration from using web applications that make good use of
I want to create tree structure using web service. I have used bottom up
I'm using Web Services to run some reports created in iReport on JasperReports Server.

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.