PHP DOMXPath为/ @ ID提供空字符串 [英] PHP DOMXPath gives empty string for /@ID

查看:185
本文介绍了PHP DOMXPath为/ @ ID提供空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简化HTML

<tr>
<td class="orderOverviewAnotherColumn">0177-4066356</td>
<a name="orderTableSorted:orderTable:10:j_id504" id="orderTableSorted:orderTable:10:j_id504" href="#">
</tr>
<tr>
<td class="orderOverviewAnotherColumn">0177-4066357</td>
<a name="orderTableSorted:orderTable:11:j_id504" id="orderTableSorted:orderTable:11:j_id504" href="#">
</tr>
<tr>
<td class="orderOverviewAnotherColumn">0177-4066358</td>
<a name="orderTableSorted:orderTable:12:j_id504" id="orderTableSorted:orderTable:12:j_id504" href="#">
</tr>
<tr>
<td class="orderOverviewAnotherColumn">0177-4066359</td>
<a name="orderTableSorted:orderTable:13:j_id504" id="orderTableSorted:orderTable:13:j_id504" href="#">
</tr>

在PHP中使用以下代码

Using the following Code in PHP

libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile('448713409.html');
$xpath = new DOMXPath($doc);
$vRes = $xpath->query(".//*[@id='orderTableSorted:orderTable:tbody_element']/tr[contains(.,'4066356')]//a[contains(@id,':j_id504')]/@ID");

foreach ($vRes as $obj) {
    $clean[] = $obj->nodeValue;
}

$clink = implode(" ",$clean);
var_dump($clink);

返回...

string(0) ""

使用Firebug Xpath Checker返回ID orderTableSorted:orderTable: 10 :j_id504,我需要找到。

Using Firebug Xpath Checker it returns the ID "orderTableSorted:orderTable:10:j_id504" which i need to find.

任何帮助正确的方向是非常感谢。 >

Any Help in the right direction is much appreciated.

推荐答案

XPath是区分大小写的语言。因此, id ID 是完全不同的事情。在您的HTML示例中, a 元素具有一个属性 id ,但没有一个称为 ID 。这就是为什么查询不会产生任何结果。

XPath is a case-sensitive language. Therefore, id and ID are entirely different things. In your HTML sample, the a elements have an attribute id, but none that is called ID. That's why the query does not yield any results.

在您的路径表达式的最后,小写 ID / p>

Lowercase ID at the very end of your path expression:

//a[contains(@id,':j_id504')]/@id

我怀疑Firebug在实际的HTML中没有返回大写的 ID

I doubt that Firebug returns an uppercase ID when in the actual HTML there is none.

这篇关于PHP DOMXPath为/ @ ID提供空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆