I have written a console application to fetch some information from a web server, convert it into XML and save it. I have manually created XML (append string using StringBuilder). As the XML might be very large is it better to use StringBuilder or XMLDocument class etc as far as memory is concerned?
To be precise my question is that if XML is like 10mb text is it memory efficient to use StringBuilder.append("") or System.XML namespace?
I think a more efficient way would be to use StringBuilder but saving the XML to a file on HD after every iteration and clearing the stringbuilder object. Any comments?
Thanks in advance. 🙂
Neither; I’d use an
XmlWriter:This avoids having to buffer a lot of data in memory, which both
StringBuilderandXmlDocumentwould do, and avoids all the encoding problems you will face if creating the xml manually (not a good idea, to be honest).