我在一张桌子上开了几张桌子,我使用的是:php×path。
I m using a series of xpaths because I m breaking up the code into conceptual units across several methods calls, and this structure has been working perfectly in other scenarios without nested tables.
该法典:
// create a host DOM document
$dom = new DOMDocument();
// load the html string into the dom
$dom->loadHTML($html_string);
// make an xpath object out of the dom
$xpath = new DOMXpath($dom);
// run query to extract the rows from the master table
$context_nodes = $xpath->query( //table[@id="id1"]/tr[position()>1] );
// parse data from the individual tables nested in each master table row
foreach($context_nodes as $context_node){
$interesting_nodes[] = $xpath->query( table[2]/tr[td[2]] , $context_node);
}
由此产生的利息——计票阵列中有空的DOMNodeLists。
斜体是DOMNodeList,含有有效数据。 每一美元目录的html内容就这样:
<td>
<table></table>
<table>
<tr>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</td>
I tried the following simplified $intesting_nodes query to match any table:
$intesting_nodes[] = $xpath->query( table , $context_node);
但是,这仍然产生同样的空洞的DOMNodeLists。
www.un.org/Depts/DGACM/index_spanish.htm 现在有趣的部分是。
当我尝试一笔利息——不问:
$interesting_nodes[] = $xpath->query( *[2]/*[*[2]] , $context_node);
Then everything works perfectly; but if I replace any "*" with the corresponding "table", "tr", or "td" tags, then the query breaks once again.
是否有任何其他人在这种行为方面经历过?
我非常希望能够利用更确切的问询,并且希望能够像现在这样保持问答,而不是把它变成绝对的。