New Features in the XmlWriter Class
The Microsoft .NET Framework version 2.0 includes many design and functionality changes to the XmlWriter class.
XmlWriter Creation
The Create method is the preferred mechanism for obtaining XmlWriter objects. The Create method uses the XmlWriterSettings class to specify which features the XmlWriter instance should support.
For more information, see Creating XML Writers.
Data Conformance
XmlWriter objects created by the Create method are, by default, more conformant than the XmlTextWriter implementation. Using the Create method and the XmlWriterSettings class offers two additional conformance-checking features.
Character checking
The XmlWriterSettings.CheckCharacters property configures the XmlWriter to check characters in the XML data stream to ensure that all characters are within the range of legal XML characters. Character checking includes checking for illegal characters in text nodes and XML names, as well as checking validity of XML names (for example, an XML name may not start with a numeral). If the XML data does not fall within the range of legal XML characters, an XmlException is thrown.
Conformance Checking
The XmlWriterSettings.ConformanceLevel property configures the XmlWriter to check and guarantee that the stream being read complies with a certain set of rules. Depending on the conformance level that is specified, the XML data can be checked to see that it conforms to the rules for a well-formed XML 1.0 document, or document fragment. If the data is not in conformance, an XmlException is thrown.
For more information, see Data Conformance and the XmlWriter.
Type Support
The XmlWriter class enables you to write values as simple-typed common language runtime (CLR) values.
You can use the WriteValue method to pass values using system types rather than strings. This enables you to write values directly without having to manually perform value conversions.
For more information, see Writing Typed Data.