[xml] GROS PROBLÈME XML AVEC DOM
Snip714
Messages postés
240
Date d'inscription
Statut
Membre
Dernière intervention
-
Chronos -
Chronos -
Bonjour, voici mon script php :
Et mon fichier XML :
...par exemple.
Le problème est que, une fois sur deux, ça me met :
Avez vous une quelconque solution ??
Merci infiniment,
<? $xml = new DomDocument(); $xml->load('bourse.xml'); $elements = $xml->getElementsByTagName('bourse'); $element = $elements->item(0); $child = $element->childNodes; foreach($child as $enfant) { $nom = $enfant->nodeName; if ($nom == "acier") { $ac = $enfant->nodeValue; } elseif ($nom == "hydro") { $hy = $enfant->nodeValue; } elseif ($nom == "oxy") { $ox = $enfant->nodeValue; } elseif ($nom == "soufre") { $so = $enfant->nodeValue; } elseif ($nom == "xenon") { $xe = $enfant->nodeValue; } elseif ($nom == "titane") { $ti = $enfant->nodeValue; } elseif ($nom == "lithium") { $li = $enfant->nodeValue; } elseif ($nom == "zinc") { $zi = $enfant->nodeValue; } elseif ($nom == "mercure") { $me = $enfant->nodeValue; } elseif ($nom == "uranium") { $ur = $enfant->nodeValue; } elseif ($nom == "energie") { $en = $enfant->nodeValue; } } class Ressource { public $value; public $less; public $most; public $incrl; public $incrm; public $div; function __construct() { $this->div = 1000; } function make($val, $les, $mos, $inl, $inm) { $this->value = $val; $this->less = $les; $this->most = $mos; $this->incrl = $inl; $this->incrm = $inm; } function update() { $incr = rand($this->incrl, $this->incrm); $this->value += $incr / $this->div; if ($this->value <= $this->less) { $this->value += 2 * $this->incrm / 1000; } elseif ($this->value >= $this->most) { $this->value -= 2 * $this->incrm / 1000; } } } $acier = new Ressource(); $acier->make($ac, 0.4, 123, -480, 500); $acier->update(); $hydro = new Ressource(); $hydro->make($hy, 0.5, 156, -470, 490); $hydro->update(); $oxy = new Ressource(); $oxy->make($ox, 0.5, 156, -470, 490); $oxy->update(); $soufre = new Ressource(); $soufre->make($so, 0.4, 217, -430, 450); $soufre->update(); $xenon = new Ressource(); $xenon->make($xe, 0.8, 1209, -280, 300); $xenon->update(); $titane = new Ressource(); $titane->make($ti, 0.6, 213, -440, 460); $titane->update(); $lithium = new Ressource(); $lithium->make($li, 0.3, 513, -730, 750); $lithium->update(); $zinc = new Ressource(); $zinc->make($zi, 0.6, 190, -440, 460); $zinc->update(); $mercure = new Ressource(); $mercure->make($me, 0.7, 784, -530, 550); $mercure->update(); $uranium = new Ressource(); $uranium->make($ur, 0.9, 2165, -820, 840); $uranium->update(); $energie = new Ressource(); $energie->make($en, 0.5, 490, -540, 560); $energie->update(); $file = fopen("bourse.xml", "r+"); $line = fputs($file, '<?xml version="1.0"?> <bourse> <acier>'.$acier->value.'</acier> <hydro>'.$hydro->value.'</hydro> <oxy>'.$oxy->value.'</oxy> <soufre>'.$soufre->value.'</soufre> <xenon>'.$xenon->value.'</xenon> <titane>'.$titane->value.'</titane> <lithium>'.$lithium->value.'</lithium> <zinc>'.$zinc->value.'</zinc> <mercure>'.$mercure->value.'</mercure> <uranium>'.$uranium->value.'</uranium> <energie>'.$energie->value.'</energie> </bourse>'); fclose($file); ?>
Et mon fichier XML :
<bourse> <acier>1.163</acier> <hydro>0.884</hydro> <oxy>1.348</oxy> <soufre>0.933</soufre> <xenon>0.864</xenon> <titane>0.995</titane> <lithium>1.417</lithium> <zinc>0.657</zinc> <mercure>1.65</mercure> <uranium>1.358</uranium> <energie>1.505</energie> </bourse>
...par exemple.
Le problème est que, une fois sur deux, ça me met :
Warning: DOMDocument::load() [function.DOMDocument-load]: Extra content at the end of the document in /mnt/140/sdb/1/8/0tt0k4r/bourse.xml, line: 14 in /mnt/140/sdb/1/8/0tt0k4r/bourse.php on line 57 Warning: Invalid argument supplied for foreach() in /mnt/140/sdb/1/8/0tt0k4r/bourse.php on line 62
Avez vous une quelconque solution ??
Merci infiniment,
A voir également:
- [xml] GROS PROBLÈME XML AVEC DOM
- Xml download - Télécharger - Édition & Programmation
- Office xml handler - Télécharger - Traitement de texte
- Driveimage xml - Télécharger - Sauvegarde
- Le XML A quoi ca sert? ✓ - Forum Programmation
- Crush dom tom - Forum Mobile
3 réponses
Vas voir ici si c'est toujours d'actualité ;)
https://www.developpez.net/forums/d73221/php/bibliotheques-frameworks/dom-methode-domdocument-load-echoue/#post489051
https://www.developpez.net/forums/d73221/php/bibliotheques-frameworks/dom-methode-domdocument-load-echoue/#post489051