XmlWriterSettings Constructor
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the XmlWriterSettings class.
public:
XmlWriterSettings();
public XmlWriterSettings ();
Public Sub New ()
Examples
The following example creates an XmlWriter object that uses the TAB character for indentation.
using System;
using System.IO;
using System.Xml;
using System.Text;
public class Sample {
public static void Main() {
XmlWriter writer = null;
try {
// Create an XmlWriterSettings object with the correct options.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = ("\t");
settings.OmitXmlDeclaration = true;
// Create the XmlWriter object and write some content.
writer = XmlWriter.Create("data.xml", settings);
writer.WriteStartElement("book");
writer.WriteElementString("item", "tesing");
writer.WriteEndElement();
writer.Flush();
}
finally {
if (writer != null)
writer.Close();
}
}
}
Imports System.IO
Imports System.Xml
Imports System.Text
Public Class Sample
Public Shared Sub Main()
Dim writer As XmlWriter = Nothing
Try
' Create an XmlWriterSettings object with the correct options.
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = true
settings.IndentChars = (ControlChars.Tab)
settings.OmitXmlDeclaration = true
' Create the XmlWriter object and write some content.
writer = XmlWriter.Create("data.xml", settings)
writer.WriteStartElement("book")
writer.WriteElementString("item", "tesing")
writer.WriteEndElement()
writer.Flush()
Finally
If Not (writer Is Nothing) Then
writer.Close()
End If
End Try
End Sub
End Class
Remarks
The following table shows initial property values for an instance of XmlWriterSettings.
Property | Initial Value |
---|---|
Async | false . |
CheckCharacters | true . |
CloseOutput | false . |
ConformanceLevel | Document. |
Encoding | Encoding.UTF8 . |
Indent | false . |
IndentChars | Two spaces. |
NewLineChars | \r\n (carriage return, line feed) for non-Unix platforms, or \n (line feed) for Unix platforms. |
NewLineHandling | Replace. |
NewLineOnAttributes | false . |
OmitXmlDeclaration | false . |
WriteEndDocumentOnClose | true . |
Applies to
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET