Jako nowy użytkownik i początkujący programista PHP - proszę o małą pomoc

Jestem w trakcie tworzenia małej aplikacji webowej która będzie przetwarzać pewne dane...
Dane z formularza idą do pliku, który tworzy plik xml - i do tego momentu wszystko działa.
Problem polega na tym, że potrzebuje do tego pliku dopisywać dane (co kliknięcie wypełnionego formularza),
jednak kiedy dopisuje kolejne dane stare zostają nadpisane nowymi


plik.php::
$dom = new DomDocument(); $dom->load($file); // FIGURA $figura = $dom->createElement("figura"); $dom->appendChild($figura); // SHAPE $shape = $dom->createElement("shape"); $shape->nodeValue = $name; $figura->appendChild($shape); // PKT A $A = $dom->createElement("A"); $figura->appendChild($A); $x1 = $dom->createElement("x"); $x1->nodeValue = $ax; $A->appendChild($x1); $y1 = $dom->createElement("y"); $y1->nodeValue = $ay; $A->appendChild($y1); // PKT B $B = $dom->createElement("B"); $figura->appendChild($B); $x2 = $dom->createElement("x"); $x2->nodeValue = $bx; $B->appendChild($x2); $y2 = $dom->createElement("y"); $y2->nodeValue = $by; $B->appendChild($y2); // PKT C $C = $dom->createElement("C"); $figura->appendChild($C); $x3 = $dom->createElement("x"); $x3->nodeValue = $cx; $C->appendChild($x3); $y3 = $dom->createElement("y"); $y3->nodeValue = $cy; $C->appendChild($y3); // PKT D $D = $dom->createElement("D"); $figura->appendChild($D); $x4 = $dom->createElement("x"); $x4->nodeValue = $dx; $D->appendChild($x4); $y4 = $dom->createElement("y"); $y4->nodeValue = $dy; $D->appendChild($y4); // promień R $R = $dom->createElement("R"); $R->nodeValue = $r; $figura->appendChild($R); $dom->save($file);
Szczerze nie wiem jak sobie z tym poradzić. Prosze o pomoc

Problem rozwiązany
.. $xpath = new DOMXPath($dom); $result = $xpath->query('//figura'); if ($result->length == 1) { $figura = $result->item(0); } else { // FIGURA $figura = $dom->createElement("figura"); $dom->appendChild($figura); } ..
btw... mało aktywne to forum...