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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:04:22+00:00 2026-06-07T10:04:22+00:00

I have just learned about XPath and I am wanting to read data from

  • 0

I have just learned about XPath and I am wanting to read data from only certain columns in a table.

My current code looks like this:

<?php

$file_contents = file_get_contents('test.html');

$dom_document = new DOMDocument();

$dom_document->loadHTML($file_contents);

//use DOMXpath to navigate the html with the DOM
$dom_xpath = new DOMXpath($dom_document);

$elements = $dom_xpath->query("//tr[@class='rowstyle']");

if (!is_null($elements)) {
    foreach ($elements as $element) 
    {
        echo $element->nodeValue . '<br />';
    }
}
else
{
    echo 'none';
}

?>

Also a variation in the query because through my research I have seen lots of issues with nest table elements but it produces the same result:

$elements = $dom_xpath->query("//table[@class='tablestyle']/tbody/tr[@class='rowstyle']");

It does grab the row of data but it makes into a single string, combining all of the cells into one string and making the tags disappear.

What I really want to do is separate those cells and grab the certain row number.

I am also curious on how to find out which version of XPath I have… My PHP version is 5.3.5

  • 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-07T10:04:24+00:00Added an answer on June 7, 2026 at 10:04 am

    Its not combining those cells… youre outputting the nodeValue which in this case is behaving like innerHTML. IF you want to work on the cells themselves the either use childNodes or a xpah query using the row as the context, then loop over the cells.

    Example:

    $dom_xpath = new DOMXpath($dom_document);
    
    $elements = $dom_xpath->query("//tr[@class='rowstyle']");
    foreach ($elements as $element) 
    {
      foreach($element->childNodes as $cell) {
         echo $cell->nodeValue . '<br />';
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just learned (the hard way) that Java Component s can only have one
I'm new to MySQL, and just learned about the importance of data normalization. My
I've only just recently learned about Google's programming language, Go. I've been intrigued by
I have just learned about recursion in Python and have completed assignments, one of
I have just learned about the possibility to use OTHER_CODE_SIGN_FLAGS to specify the keychain
I have just learned about Android nine-patches idea, and it is a pretty good
I just learned about how the Java Collections Framework implements data structures in linked
A lot of what I have learned about VB I learned from using Static
I have just started learning about socket programming and learned about winsock and achieved
I am new to Box2d, and I have just learned that it does not

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.