I have an array
$arr=array("A","B","C");
and I want to create a multi level XML from that like
<root>
<error>
<A>
<B>
<C>
<D/>
</C>
</B>
</A>
</error>
</root>
and I have written the code as
$arr = array("A", "B", "C", "D");
$doc = new DomDocument();
$doc->formatOutput=true;
$doc->LoadXML('<root/>');
$root = $doc->documentElement;
$errorgroup = $doc->createElement('error');
$root->appendChild($errorgroup);
foreach($arr as $erreur) {
$missinggroup = $doc->createElement($erreur);
$errorgroup->appendChild($missinggroup);
$errorgroup=$doc->createElement($erreur);
}
echo $doc->saveXml();
but the output is only displaying <A/> in the XML inside error and not the rest B and C. Where am I going wrong here?