I recently created a small C# windows forms/LINQ to XML app in VS2010 that does exactly what it\'s supposed to do, except for one thing: it adds \"[]\" to the end of the DOC
Evidently, when XDocument parses an XML document that contains a Document Type Declaration, an empty "internal subset" is automatically inserted if one doesn't exist. (The internal subset is the part surrounded by [] in the ).
The result is well-formed XML. However, if your legacy system can't handle it, you can remove the internal subset from the DTD by setting the XDocumentType.InternalSubset property to null:
XDocument document = ...;
if (document.DocumentType != null)
document.DocumentType.InternalSubset = null;