dom in PHP saves new content over the old File

124 views Asked by At

Each time i do

$country = $this->dom->saveXML(); // put string in country 
$this->dom->save('country.xml');

It delets the old country.xml and creates a new country.xml how can i append the old content of country.xml to the new content and save it again as country.xml

2

There are 2 answers

3
Sean On BEST ANSWER

Rather than trying to append it to the file, have you considered appending the new data to the existing 'old' DOM and then saving that to country.xml? This way will keep the document consistent and valid.

2
tloach On

If I understand correctly then you want to append the new XML to the end of the old file? This is a bit unusual for XML, however you could do it simply by writing to the file using

file_put_contents('country.xml', $country, FILE_APPEND);

rather than

$this->dom->save('country.xml');