I currently have some code that directly instantiates an XmlTextWriter object, which allows me to set the quote char to a single quote (which I need in order to generate XML to match a legacy system). EG
var fred = new XmlTextWriter(stream, encoding);
fred.QuoteChar = '\'';
However in Microsoft's documentation for XmlTextWriter class they state:
Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.
The XmlWriterSettings Class allows you to set various attributes, but the quote character is not one of them, and the XmlWriter class does not expose the quote character like the XmlTextWriter does.
I want to move to XmlWriter as it also solves an indentation problem I have that is not easily solved with the XmlTextWriter, but I still need to set the quote character.
How can I set the quote character in a XmlWriter class?
Technically this is a duplicate of the listed question Can one force XMLWriter to write elements in single quotes?. But If you follow the links in the only answer there you get to a solution for setting the quote character on a XmlTextWriter class. The exact opposite of what I am asking to do.
XmlTextWriter. None of the internal implementation classes used byXmlWriterhas an option for that (not even an internal or private switch). Disclaimer: I only browsed the disassembly forSystem.Xmlon my machine (.NET 4.7), other versions might conceivably behave differently. - Jeroen MostertXmlTextWriter- Peter MXmlWriteryourself. You can "mostly" wrap aroundXmlTextWriterwhen it does what you want, and do something else when it doesn't. Relying on the Framework classes to do these highly specific things for you (and continuing to do them in new versions) seems unwise. (XmlTextWriterisn'tsealed, so deriving from it is also an option, but I'm not sure how far that gets you.) - Jeroen Mosterttag1in<tag1 /><tag2>Data</tag2>and thinks thattag1contains "Data" - Peter M