DOMXPath 查询以获取 table 列中复选框的名称

DOMXPath query to get the name of the check boxes in a table column

我有以下 html table 结构

<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)
}

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

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

$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');
}