I will only use the DOM API as a last resort. As Jon said, LINQ to XML is another way. But, whatever you do Whatever, don’t go back to string formatting, because you need the correct namespace, entity references, attribute references and other subtleties.
Create XML in .NET The documentation seems to have many options. What is the best way?
XmlWriter has a nice interface for creating documents in a streaming manner. It is most effective if you have a recursive structure that needs to be mapped to XML.
I will only use the DOM API as a last resort. As Jon said, LINQ to XML is another way. But, whatever you do, don’t go back to string formatting, because You need correct namespaces, entity references, attribute references and other subtleties.