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

  • Home
  • SEARCH
  • 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 8397523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:48:42+00:00 2026-06-09T20:48:42+00:00

I am trying to access a specific element of the Dom using XPath Here

  • 0

I am trying to access a specific element of the Dom using XPath

Here is an example

<table>
<tbody>
    <tr>
        <td>
            <b>1</b> <a href="http://www.url.html">data</a><br>
            <b>2</b> <a href="http://www.url.html">data</a><br>
            <b>3</b> <a href="http://www.url.html">data</a><br>
        </td>
    </tr>
</tbody>
</table>

I want to target “table td” so my query in Xpath is something like

$finder->query('//table/td');

only this doesn’t return the td as its a sub child and direct access would be done using

$finder->query('//tr/td');

Is there a better way to write the query which would allow me to use something like the first example ignoring the elements in-between and return the TD?

  • 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-09T20:48:44+00:00Added an answer on June 9, 2026 at 8:48 pm

    Is there a better way to write the query which would allow me to use
    something like the first example ignoring the elements in-between and
    return the TD?

    You can write:

    //table//td
    

    However, is this really “better”?

    In many cases the evaluation of the XPath pseudo-operator // can result in significant inefficiency as it causes the whole subtree rooted in the context-node to be traversed.

    Whenever the path to the wanted nodes is statically known, it may be more efficient to replace any // with the specific, known path, thus avoiding the complete subtree traversal.

    For the provided XML document, such expression is:

    /*/*/tr/td
    

    If there is more than one table element, each a child of the top element and we want to select only the tds of the forst table, a good, specific expression is:

    /*/table[1]/*/tr/td
    

    If we want to select only the first td of the first table in the same document, a good way to do this would be:

    (/*/table[1]/*/tr//td)[1]
    

    Or if we want to select the first td in the XML document (not knowing its structure in advance), then we could specify this:

    (//td)[1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an access control system. Here's a stripped down example of
I'm trying to access a specific window using its handle (that is System.IntPtr value):
Trying to prevent access to a specific file, not any files with a certain
I am trying to check if I have write access to a specific key
I am trying to access all the data from database listOfFolder table folder and
Hi I'm trying to access a WCF service which returns a JSON Array using
I am trying to access an exchange server to read emails from a specific
I am trying to delete all specific key element in my linked list in
Basically I am trying to configure Access to a specific Folder on my shared
The specific area I'm trying to access is the body of the New Email

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.