foreach shows attributes of first xml node only



I am trying to display attributes foreach global_ivr_variable:



$xml = '
<response method="switchvox.ivr.globalVariables.getList">
<result>
<global_ivr_variables>
<global_ivr_variable id="1" name="cid_name" value="Smith" />
<global_ivr_variable id="2" name="Q_ID_Global" value="COS" />
</global_ivr_variables>
</result>
</response>
';

$sxml = simplexml_load_string($xml);

foreach($sxml->result->global_ivr_variables->global_ivr_variable->attributes() as $a => $b)
{
echo $a .'=' . $b . "<br>";
}


All I get is the attributes of the first node:



id="1"
name="cid_name"
value="Smith"


I've also tried the following, which gives me no values at all...



foreach($sxml->result->global_ivr_variables as $xvar)
{
$a = $xvar->global_ivr_variable->id;
$b = $xvar->global_ivr_variable->name;
$c = $xvar->global_ivr_variable->value;
echo 'a='.$a.', b='.$b.', c='.$c.'<br>';
}

a=, b=, c=


Thank you all who step up to help the needy!


No comments:

Post a Comment