This topic has not yet been rated - Rate this topic

XmlWriterSettings Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Specifies a set of features to support on the XmlWriter object created by the XmlWriter.Create method.

System.Object
  System.Xml.XmlWriterSettings

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public sealed class XmlWriterSettings

The XmlWriterSettings type exposes the following members.

  Name Description
Public method Supported by the XNA Framework Supported by Portable Class Library XmlWriterSettings Initializes a new instance of the XmlWriterSettings class.
Top
  Name Description
Public property Async Gets or sets a value that indicates whether asynchronous XmlWriter methods can be used on a particular XmlWriter instance.
Public property Supported by the XNA Framework Supported by Portable Class Library CheckCharacters Gets or sets a value indicating whether to do character checking.
Public property Supported by the XNA Framework Supported by Portable Class Library CloseOutput Gets or sets a value indicating whether the XmlWriter should also close the underlying stream or TextWriter when the Close method is called.
Public property Supported by the XNA Framework Supported by Portable Class Library ConformanceLevel Gets or sets the level of conformance which the XmlWriter complies with.
Public property DoNotEscapeUriAttributes Gets or sets a value that indicates whether the XmlWriter do not escape URI attributes.
Public property Supported by the XNA Framework Supported by Portable Class Library Encoding Gets or sets the type of text encoding to use.
Public property Supported by the XNA Framework Supported by Portable Class Library Indent Gets or sets a value indicating whether to indent elements.
Public property Supported by the XNA Framework Supported by Portable Class Library IndentChars Gets or sets the character string to use when indenting. This setting is used when the Indent property is set to true.
Public property Supported by Portable Class Library NamespaceHandling Gets or sets a value that indicates whether the XmlWriter should remove duplicate namespace declarations when writing XML content. The default behavior is for the writer to output all namespace declarations that are present in the writer's namespace resolver.
Public property Supported by the XNA Framework Supported by Portable Class Library NewLineChars Gets or sets the character string to use for line breaks.
Public property Supported by the XNA Framework Supported by Portable Class Library NewLineHandling Gets or sets a value indicating whether to normalize line breaks in the output.
Public property Supported by the XNA Framework Supported by Portable Class Library NewLineOnAttributes Gets or sets a value indicating whether to write attributes on a new line.
Public property Supported by the XNA Framework Supported by Portable Class Library OmitXmlDeclaration Gets or sets a value indicating whether to omit an XML declaration.
Public property Supported by the XNA Framework OutputMethod Gets the method used to serialize the XmlWriter output.
Public property WriteEndDocumentOnClose Gets or sets a value that indicates whether the XmlWriter will add closing tags to all unclosed element tags when the Close() method is called.
Top
  Name Description
Public method Supported by the XNA Framework Supported by Portable Class Library Clone Creates a copy of the XmlWriterSettings instance.
Public method Supported by the XNA Framework Supported by Portable Class Library Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by the XNA Framework Supported by Portable Class Library Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by the XNA Framework Supported by Portable Class Library GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method Supported by the XNA Framework Supported by Portable Class Library GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method Supported by the XNA Framework Supported by Portable Class Library MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Supported by the XNA Framework Supported by Portable Class Library Reset Resets the members of the settings class to their default values.
Public method Supported by the XNA Framework Supported by Portable Class Library ToString Returns a string that represents the current object. (Inherited from Object.)
Top

The Create method is the preferred mechanism for obtaining XmlWriter instances. The Create method uses the XmlWriterSettings class to specify which features to implement in the created XmlWriter object.

Note Note

If the XmlWriter is being used with the Transform method, you should use the OutputSettings property to obtain an XmlWriterSettings object with the correct settings. This ensures that the created XmlWriter object has the correct output settings.

For more information, see Creating XML Writers.

The following example creates an XmlWriter that writes to an XML file and writes each attribute on a new line.


XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.NewLineOnAttributes = true;

writer = XmlWriter.Create(Console.Out, settings);

writer.WriteStartElement("order");
writer.WriteAttributeString("orderID", "367A54");
writer.WriteAttributeString("date", "2001-05-03");
writer.WriteElementString("price", "19.95");
writer.WriteEndElement();
	
writer.Flush();


The sample produces the following output:

<order
  orderID="367A54"
  date="2001-05-03">
  <price>19.95</price>
</order>

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 8 Release Preview, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)