The underlying reader used by XmlDocument
(which uses XmlTextReader
) does not distinguish between a document with an empty internal subset and one with no internal subset specified, so it will return InternalSubset == ""
for both cases.
Then when XmlDocument.Save()
is called, it sees an empty string for InternalSubset
and dutifully writes an empty internal subset: []
.
Unfortunately, XmlDocument.DocumentType.InternalSubset
is readonly, so you cannot set it to null. You can either do:
Use the lower level XmlTextWriter.WriteDocType()
to have more control.
Use XDocument
, where you can set XDocument.DocumentType.InternalSubset = null
.