0

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 !!!

1
  • instead attribute @val i use for!! Commented Nov 14, 2013 at 16:24

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.