1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| function generateXMLDocument(DOMDocument $xmlhdlr, Array $Xml_elements, Array $GivenData, $filename = "test.xml")
{
foreach($Xml_elements as $category => $Elements)
{
$bCreateCategory = false;
$i = 0;
$TagsToAppend = Array(); // Déclaration d'un tableau qui contiendra les balises à ajouter
foreach($Elements as $label => $Definition)
{
$name = $Definition[0];
foreach($GivenData as $ref => $content)
{
if($ref == $name)
{
$new_element = $xmlhdlr->createElement($ref);
$new_textNode = $xmlhdlr->createTextNode($content);
$new_element->appendChild($new_textNode);
$TagsToAppend[ $i++ ] = $new_element;
$bCreateCategory = true;
}
}
}
$res = $xmlhdlr->getElementsByTagName($category);
if($res->length < 1 && $bCreateCategory == true) // Créer catégorie si elle n'existe pas
{
$new_category = $xmlhdlr->createElement($category);
foreach($TagsToAppend as $new_tag)
$new_category->appendChild($new_tag);
$xmlhdlr->appendChild($new_category);
var_dump($new_category);
echo "<br/><br/>";
}
}
$xmlhdlr->save($filename);
echo "document saved ... <br/>";
} |
Partager