Reputation: 62
Using XPath,How to select specific attributes value of node(where attribute = quantity)?
For Example:
$xml = new SimpleXMLElement('
<option name="Size">
<value optionID="147" quantity="1">6</value>
<value optionID="111" quantity="1">7</value>
<value optionID="145" quantity="0">8</value>
<value optionID="112" quantity="0">9</value>
<value optionID="146" quantity="0">10</value>
<value optionID="416" quantity="0">11</value>
</option>
');
Right Now I using the following code for getting value of size:
foreach ($product->xpath('//option[@name="Size"]) as $item)
{
foreach ($item->children() as $child)
{
echo $child ."\n";
}
}
Now i want to get value of quantity with size. So plese help me how to make change in XPath Query for getting "quantity" value?
Upvotes: 1
Views: 2309
Reputation: 20748
You can get "quantity" attributes of children "value" nodes using this XPath expression:
//option[@name="Size"]/value/@quantity
Upvotes: 1