I’m looking for a DOM XML function to convert PHP array like this:
<?php
$errors = array("A", "B", "C", "D");
?>
to DOM XML NodeList
<?xml version="1.0" standalone="no"?>
<error>
<missing>A</missing>
<missing>B</missing>
<missing>C</missing>
<missing>D</missing>
</error>
Thank you very much for your help 🙂
I tried the following code:
<?php
$basedoc = new DomDocument();
$basedoc->Load("Standard.svg"); //Fichier SVG de base
$baseroot = $basedoc->documentElement; //On prend l'élément racine
$errorgroup = $basedoc->createElement('error'); //On crée le groupe de base
foreach($erreurs as $erreur) {
$missinggroup = $errorgroup->createElement('missing'); //On crée le groupe de base
$errorgroup->appendChild($missinggroup);
}
$baseroot->appendChild($errorgroup);
?>
You are not not using
$erreuranywhere in the creation code so obviously it wont be in the resulting XML. Also, you cannot create an Element from aDOMElementbut must create it from theDOMDocument. Your code will give a Fatal Error.Change
to
and then it will work: http://codepad.org/GmCIBIQW