Get td values with loadHTML and DOMXPath
I'm trying to get the td values from a table, using loadHTML and DOMXPath,
but even though there are no errors, the nodes always return empty on both
"textContent" and "nodeValue".
The table id is "akas", but nothing else inside the table has id's or
classes.
Here's my code:
$xml = new DomDocument();
$xml->validateOnParse = true;
libxml_use_internal_errors(true);
$xml->loadHTML($data); //$data contains all the HTML
$xpath = new DOMXPath($xml);
$table = $xpath->query('//table[@id="akas"]')->item(0);
$rows = $table->getElementsByTagName("tr");
foreach($rows as $row)
{
$cells = $row -> getElementsByTagName('td');
foreach ($cells as $cell) print $cell->nodeValue;
}
There are no errors, but I can't get anything from the nodes, if I do a
var_dump every attribute returns empty, except for the [tagName] and
[nodeName]. "Length" of the table returns the correct value (the number of
tr's and/or td's inside).
What could be wrong? Can anyone shed some light on this?
No comments:
Post a Comment