Same comments here, you are storing the data here twice. Ideally the code should use a xml sax parser (http://php.net/manual/en/book.xml.php) to use a low profile memory footprint. You will also have important speed up.