The problem isn't creating the XML file. The problem is querying it later, after you've dumped it from RAM to disk, you have to load the entire thing off disk back into RAM in order to rebuild the DOM.
A database like SQLite allows you to perform structured queries at faster-than-O(n) speed straight off the disk.