user2992919
user2992919

Reputation: 3

PHP and simplexml

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

Answers (1)

Marc B
Marc B

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

Related Questions