Home > database >  array Xpath 'name' 'value'
array Xpath 'name' 'value'

Time:12-17

from this html code I have to extract two values, two separate fields: the first in 'name' and the second in 'value'

<table>
<tbody>
<tr>
<td>
<span><strong>CPU &amp; Dissipatore&nbsp;</strong></span>
</td>
<td>
<span>Intel i7-11700K Dissipatore a Liquido 240mm&nbsp;</span>
</td>
</tr>
</table>

Xpath code:

array(
    'name' => ".//table//tr//td[1]",
    'value' => ".//table//tr//td[2]",
),

So I get nothing. What am I doing wrong?

CodePudding user response:

Like this:

//tr//td/span

Output

CPU & Dissipatore 
Intel i7-11700K Dissipatore a Liquido 240mm 

CodePudding user response:

Name/value pairs in XPath (3.1) would be maps not arrays so in XPath 3.1 you can use e.g.

map {
  'name' : //table//tr//td[1]/string(),
  'value' : //table//tr//td[2]/string()
}

Online sample.

CodePudding user response:

my code seems to be XPath 1.0, php wordpress plugin

public function getFeaturesXpath()
 {
     return array(
         array(
             'name' => ".//table//tr//td[1]",
             'value' => ".//table//tr//td[2]",
         ),
     );
 }
  • Related