Bonjour et merci pour ta réponse Soundboy39.
Mais j'ai du mal m'exprimer.
J'ai choisi la solution de mettre a jour le document xml plutot que le créer entierement, pour garder la partie ci-dessous:
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:z="#RowsetSchema">
1 Mon probleme c'est que je souhaite ajouter la partie rs:data qui est parent de z:row, apres la balise fermante /s:Schema.
rs:data est effectivement fils de xml mais il faut que je recupere la balise xml dans une variable pour préciser quel est le parent et c'est que je ne parviens pas a faire et c'est ma question.
2 la commande "$dom = new DOMDocument();" créer automatiquement une entete xml mais il y en a deja une dans mon fichier.
il faudrait une commande genre : "$dom = update DOMDocument();"
Voici mon code pour l'instant mais évidement la commande /$xml = $dom->getElementByTagName('xml'); ne fonctionne et donc donne l'erreur suivante:
Call to a member function appendChild() on null in C:\wamp64\www\updateDomDocXMLWinMSS.php on line 49 sur la commande "$xml->appendChild($data);"
<?php
include '../inc/bdd.php';
$stagesall = $bdd->query('SELECT * FROM stages WHERE id ORDER BY date_creation_stage DESC');
$dom = new DOMDocument(); // instancie un objet DomDocument
$dom->formatOutput=true; //met au format xml au lieu de en ligne
$dom->load('new/STAGE.xml'); // Chargement d'un fichier XML
$xml = $dom->getElementById('xml'); // chercher la balise xml
//$xml = $dom->getElementByTagName('xml'); // chercher la balise xml !ICI je ne trouve pas la bonne commande
$data = $dom->createElement('rs:data'); //creer l'element parent data
// $dom->appendChild($data); //creer l'element parent
// stage
while ($row = $stagesall->fetch()) { //boucle pour recuperer la table stages
$zrow = $dom->createElement('z:row'); //creer l'element fils du parent data
$zrow->setAttribute('MatchId', $row['matchsid']); //creer attribute fils du parent z:row avec value from table
$zrow->setAttribute('StageId', $row['numstage']);
$zrow->setAttribute('StageName', $row['nomstage']);
$zrow->setAttribute('Location', '');
$zrow->setAttribute('FirearmId', $row['FirearmId']);
$zrow->setAttribute('CourseId', $row['CourseId']);
$zrow->setAttribute('ScoringId', $row['ScoringId']);
$zrow->setAttribute('TrgtTypeId', $row['TrgtTypeId']);
$zrow->setAttribute('IcsStageId', $row['IcsStageId']);
$zrow->setAttribute('Remove', '');
$zrow->setAttribute('TrgtPaper', $row['TrgtPaper']);
$zrow->setAttribute('TrgtPopper', $row['TrgtPopper']);
$zrow->setAttribute('TrgtPlates', $row['TrgtPlates']);
$zrow->setAttribute('TrgtVanish', $row['TrgtVanish']);
$zrow->setAttribute('TrgtPenlty', $row['TrgtPenlty']);
$zrow->setAttribute('ReportOn', $row['ReportOn']);
$zrow->setAttribute('MaxPoints', $row['MaxPoints']);
$zrow->setAttribute('StartPos', $row['StartPos']);
$zrow->setAttribute('StartOn', $row['StartOn']);
$zrow->setAttribute('StringCnt', $row['StringCnt']);
$zrow->setAttribute('Descriptn', $row['Descriptn']);
$data->appendChild($zrow); //creer l'element fils du parent data }
$xml->appendChild($data); //creer l'element parent
echo "<xmp>" .$dom->saveXML()."</xmp>";
$dom->save("new/STAGE.xml") or die ("Error, Unnable to create XML file.");