<p>I have some code that creates a fairly large xml DOM and writes it off to a file (up to 50-100MB) . It basically creates the DOM and then calls a toString on it and writes it out with ofstream. Is there a way to get streaming output of the generated dom so that it doesn't create the whole structure in memory all at once and then copy it, etc? I will not modify any node after i create it so it can write it out and free up the memory right away. I could write my own xml class that does the xml construction but ... i don't think that's a good idea since i'll probably miss something when it comes down to escaping etc.</p>

[{'answer_id': 51647, 'author': 'Simon Steele', 'author_id': 4591, 'author_profile': 'https://Stackoverflow.com/users/4591', 'pm_score': 1, 'selected': False, 'text': '<p>I would recommend <a href="http://www.tbray.org/ongoing/When/200x/2004/02/20/GenxStatus" rel="nofollow noreferrer">GenX</a> as a streaming XML writer, I use this in <a href="http://pnotepad.org/" rel="nofollow noreferrer">Programmer\'s Notepad</a> and it works a treat, you can see examples of use in the source code. Extremely fast, and it produces good UTF-8 XML. Memory usage while you use it should remain roughly constant.</p>\n'}, {'answer_id': 56899, 'author': 'naumcho', 'author_id': 779, 'author_profile': 'https://Stackoverflow.com/users/779', 'pm_score': 3, 'selected': True, 'text': '<p>Ok, turns out libxml2 has a streaming API:</p>\n\n<p><a href="http://xmlsoft.org/examples/testWriter.c" rel="nofollow noreferrer">http://xmlsoft.org/examples/testWriter.c</a></p>\n\n<p>It\'s a little old style (very C-ish) but you can write your wrapper around it.</p>\n'}, {'answer_id': 823725, 'author': 'Ben Bryant', 'author_id': 28953, 'author_profile': 'https://Stackoverflow.com/users/28953', 'pm_score': 0, 'selected': False, 'text': '<p>Look under keyword "C++ XML writer;" XML writers generate XML to file without building the entire DOM in memory so they don\'t need to use very much memory at all. You didn\'t mention platform, but Microsoft XmlLite has IXmlWriter.</p>\n'}, {'answer_id': 25115741, 'author': 'Václav Slavík', 'author_id': 237188, 'author_profile': 'https://Stackoverflow.com/users/237188', 'pm_score': 0, 'selected': False, 'text': '<p>There really isn\'t much to generating valid XML; the escaping that you worry about is trivial.</p>\n\n<p>There\'s a library for streaming writing of XML here: <a href="https://code.google.com/p/xml-writer-cpp/" rel="nofollow">https://code.google.com/p/xml-writer-cpp/</a> — if nothing else, it\'s useful for education purposes.</p>\n'}]
['https://Stackoverflow.com/questions/50311', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/779/']