gpt4 book ai didi

php - DOMXPath 查询以获取表列中复选框的名称

转载 作者:搜寻专家 更新时间:2023-10-31 21:25:22 24 4
gpt4 key购买 nike

我有以下html表格结构

<table id="gvPOItems">
<tbody>
<tr>
<td class="grdItemClass">
<span class="CSSchkupdatethis">
<input id="gvPOItems_cbxForShipping_0" type="checkbox" name="gvPOItems$ctl02$cbxForShipping">
</span>
</td>
<td class="grdItemClass">
<span id="gvPOItems_lblProductID_0">685029</span>
</td>
<td>
<img src="" alt="Product Photo">
</td>
<td class="grdItemClass">SWA400000009-W</td>
<td class="grdItemClass">
<span id="gvPOItems_lblPOItemID_0">
1162934PLN44532493
</span>
</td>
<td class="grdItemClass">
Small Wonder Training Set White - 300 ml
</td>
<td class="grdItemClass">
0 Months+, BPA Free, This training set is simple, easy-to-use and can be used for both girls and boys
</td>
<td class="grdItemClass">110.00</td>
<td class="grdItemClass">13.20</td>
<td class="grdItemClass">0.00000000000</td>
<td class="grdItemClass">96.80</td>
<td class="grdItemClass">
<span id="gvPOItems_lblQuantity_0">1</span>
</td>
<td class="grdItemClass">96.80</td>
<td class="grdItemClass">&nbsp;</td>
<td class="grdItemClass">&nbsp;</td>
<td>
<select name="gvPOItems$ctl02$ddlStatus" id="gvPOItems_ddlStatus_0">
<option value="0">Select</option>
<option value="Accepted">Accepted</option>
<option value="OutOfStock">OutOfStock</option>
</select>
<span id="gvPOItems_RequiredFieldValidator1_0" style="display:none;">
*
</span>
</td>
<td class="grdItemClass">48</td>
</tr>
</tbody>

我正在尝试使用 xpath 查询获取 ex: gvPOItems$ctl02$cbxForShipping 列中复选框的名称

我使用的代码是

<? php 
function xpath($content) {
$dom = new DOMDocument();
$dom->strictErrorChecking = false;
$dom->loadHTML($content);
return new DOMXPath($dom);
}

$countNode = $xpath->query('//table[@id="gvPOItems"]//tr');
for($i=0;$i<=$countNode->length;$i++){
$q= '//table[@id="gvPOItems"]/tr['.$i.']//td';
$node = $xpath->query($q);
var_dump($node->item(0));
}

但是,我得到的输出是

object(DOMNodeList)#169 (1) {
["length"]=> int(17)
}

获取列中所有复选框名称的正确查询应该是什么?

最佳答案

我已经更改了查询。您可以直接选择输入。

$xml = file_get_contents('test.xml');

function xpath($content)
{
$dom = new DOMDocument();
$dom->strictErrorChecking = FALSE;
$dom->loadHTML($content);
return new DOMXPath($dom);
}

$xpath = xpath($xml);

$countNode = $xpath->query('//table[@id="gvPOItems"]//tr');
var_dump($countNode);

$q = '//input[@type="checkbox"]'; // whole document
$q = '//table[@id="gvPOItems"]//input[@type="checkbox"]'; // only in the table
$nodeList = $xpath->query($q);
// var_dump($node);// ->item(0));
// var_dump($node->item(0));

foreach($nodeList as $node)
{
echo "path=" . $node->getNodePath();
echo "\n";
echo "name=" . $node->getAttribute('name');
}

关于php - DOMXPath 查询以获取表列中复选框的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37405189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com