i got this XML:
<shipping_line>
<article id="960382" quantity="500" />
<article id="960560" quantity="150" />
<article id="960426" quantity="250" />
<article id="1177" quantity="100" >
<product>5500070000126273</product>
<product>5500070000126264</product>
<product>5500070000126255</product>
<product>5500070000126246</product>
<product>5500070000126237</product>
</article>
</shipping_line>
and i access the article elements atributes id and quantity like this:
$atrs = $xml->xpath('//article[not(node())]/@quantity | //article[not(node())]/@id');
now i would like to access the 2 values i made a foreach like this:
foreach ($atrs as $id => $val ) {
error_log(print_r($val , true));
}
And my error log shows this:
SimpleXMLElement Object\n(\n [@attributes] => Array\n (\n [id] => 960382\n )\n\n)\n
SimpleXMLElement Object\n(\n [@attributes] => Array\n (\n [quantity] => 500\n )\n\n)\n
SimpleXMLElement Object\n(\n [@attributes] => Array\n (\n [id] => 960560\n )\n\n)\n
SimpleXMLElement Object\n(\n [@attributes] => Array\n (\n [quantity] => 150\n )\n\n)\n
SimpleXMLElement Object\n(\n [@attributes] => Array\n (\n [id] => 960426\n )\n\n)\n
SimpleXMLElement Object\n(\n [@attributes] => Array\n (\n [quantity] => 250\n )\n\n)\n
how could i access the 2 values so i can use a function like
someFunctionUsing2Values($article_no , $quantity)
Here’s how I would do it: