Parsing 需要帮助:xpath查询

Parsing 需要帮助:xpath查询,parsing,xpath,Parsing,Xpath,我想排除此表中的IMG值: <table class="info"> <tbody> <tr><th class="round-top" colspan="2">Status</th></tr> <tr class="even"> <td class="key">Schaltprogramm aktiv</td> <td class="value">

我想排除此表中的IMG值:

<table class="info">
 <tbody>
  <tr><th class="round-top" colspan="2">Status</th></tr>  
  <tr class="even">
    <td class="key">Schaltprogramm aktiv</td>
    <td class="value"><img height="15" src="./pics/ste-symbol_an-97b765.png"></td>
  </tr>
 </tbody>
</table>  
<table class="info">
 <tbody>
  <tr><th class="round-top" colspan="2">Warmwasser</th></tr>  
  <tr class="even">
    <td class="key">WW-Isttemp.</td>
    <td class="value">49,0 °C</td>
  </tr>
  <tr class="odd">
    <td class="key round-leftbottom">WW-Solltemp.</td>
    <td class="value round-rightbottom">46,5 °C</td>
  </tr>
</tbody></table>  
我必须如何排除变量“nodelist”中的IMG值

有什么想法吗?

我认为(但不确定)您希望
$nodelist
包含所有
td
元素,这些元素的
class
属性以字符串
value
开头,但如果它们包含
img
元素,则不需要

如果这是对你问题的正确解释,那就改变一下

$nodelist = $xpath->query( "//tr/td[substring(@class,1,5)='value']" );

我不清楚您想对第二个样本表中的温度值做什么;您可能需要编辑问题,以便更清楚地确定是否要检索它们

XPath是XML文档的查询语言。因此,XPath表达式不能(通过创建或删除节点)更改文档。您需要做的是将文档转换为另一个XML文档。XSLT是一种专门为XML转换而设计的语言,使用XSLT实现这种特定的转换非常简单。您是否对获取XSLT解决方案感兴趣?
$nodelist = $xpath->query( "//tr/td[substring(@class,1,5)='value']" );
$nodelist = $xpath->query( "//tr/td[substring(@class,1,5)='value'][not(img)]" );