doutang2017 2012-07-27 22:20
浏览 21
已采纳

Xpath并在同一表格行中选择不同的信息

I have an xpath query that returns the description of a td (with a width of 60) from a table row. I pull between 0 and 30 rows per query.

$textTags = $xpath->query( '//table/tr/td[@width=60]' );

each table row looks like this

<tr>
<td width=60 bgcolor='#ffffcc'><b>Description</b></td>
<td align=center width=80><img src='http://></td>
<td width=50 bgcolor='#ffffcc' align=center><b>1</b></td>
<td bgcolor='#ffffcc'><b>Toy</b></td>
<input type='hidden'  name='obj_id_3' value='20885'><input type='hidden' name='oldcost_3'  value='0'></td>
<td align=center bgcolor='#ffffcc'><input type='text' name='cost_3' size=6 maxlength=5 value='0'></td>
<td width=180 bgcolor='#ffffcc'><i>more text</i></td>
<td width=40 bgcolor='#ffffcc' align=center><select name=back_to_inv[20885]>
<tr>this continues on a max of 30 times</tr>

I run through a loop to get this info:

foreach ( $textTags as $tag ){
$item = $tag->nodeValue;
}

I get the description text I need. However, there is the 'hidden' input type with a name=obj_id_3 and a value=20885 that I need to get with each corresponding pass. How do I get those hidden input values in addition, that are part of the current tr I'm looking at? Each tr has only 1 record that I need to access so I don't have to worry about multiple, the table you see above is how every table looks, minus the unique description and hidden name and values.

  • 写回答

1条回答 默认 最新

  • doulvli9462 2012-07-27 23:08
    关注

    You can just use an or to query the input separately. Something like

    $xpath->query("//table/tr/td[@width=60]|//table/tr/input[contains(@id, 'obj_id')]");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料