Reputation: 3
i use php and simplexml, my probleme is "to add a attribute with for" my code is:
for($i=1;$i<=$compteur;$i++)
{
$jeu->situation->question->choix->addChild('rep',"\n".$rep[$i]."\n");
$jeu->situation->question->choix->rep->addAttribute('val',$i);
}
Result:
<choix>
<rep val="1">
</rep>
<rep>
</rep>
</choix>
he add just in a first !!!
Upvotes: 0
Views: 43
Reputation: 360802
addChild()
returns the node that was added to the DOM, so do your attribute work on that
$child = $jeu->situation->question->choix->addChild('rep',"\n".$rep[$i]."\n");
$child->addAttribute('val', $i);
Upvotes: 3