I'm trying to create an XMLWriter for an XDocument, and also apply settings to it, but I can't figure out how.
Here's what I have so far.
var writerSettings = new XmlWriterSettings()
{
OmitXmlDeclaration = true,
Encoding = Encoding.UTF8
};
var request = new XDocument();
using (var writer = request.CreateWriter())
{
writer.WriteStartDocument();
writer.WriteStartElement("CUSTOMER");
writer.WriteElementString("ADDRESS", "123 Fake St.");
writer.WriteElementString("CITY", "San Jose");
writer.WriteElementString("STATE", "CA");
writer.WriteEndElement();
writer.WriteEndDocument();
}
I can't figure out how to apply writerSettings to the writer. The XDocument.CreateWriter() method doesn't take any parameters to specify the XMLWriterSettings. And, after it's created, the Settings property doesn't have a setter.
If there's no way to use CreateWriter() and apply settings, how else could I accomplish something equivalent, and end up with the same result?