Can I use XDocument.Save and exclude the XML Decla

2019-05-28 15:32发布

问题:

I'm loading a XML file into a XDocument, doing stuff to it, and calling Save(fileName) to rewrite the XML file. The original file has no XML declaration, is there anyway to avoid XDocument adding a XML declaration?

回答1:

I think you'll have to use an XmlWriter. Or ToString.

Just found this article which seems to agree.