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.
Is there some reason why you can't save the DOM or other datastructures that you help you query/manipulate the XML?
A database isn't a set of flat-file CSVs even though that's all that is actually needed to do everything that people do with databases (albeit one operation at a time). (The data may be normalized but the datastructures aren't necessarily.)
Instead, a database is data together with some data structures (and relevant code) that are maintained to speed up operations on said data.
Why can't one persist auxillary datastructures for XML, including (but not limited to) the DOM?
A database like SQLite allows you to perform structured queries at faster-than-O(n) speed straight off the disk.