XmlWriterSettings 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 XmlWriterSettings 類別的新執行個體。
public:
XmlWriterSettings();
public XmlWriterSettings();
Public Sub New ()
範例
以下範例建立一個 XmlWriter 物件,使用 TAB 字元進行縮排。
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
備註
下表顯示 XmlWriterSettings實例的初始屬性值。
| 房產 | 初始值 |
|---|---|
| Async |
false。 |
| CheckCharacters |
true。 |
| CloseOutput |
false。 |
| ConformanceLevel | Document。 |
| Encoding |
Encoding.UTF8。 |
| Indent |
false。 |
| IndentChars | 兩個空位。 |
| NewLineChars |
\r\n (回車,換行)用於非 Unix 平台,或 \n (換行)用於 Unix 平台。 |
| NewLineHandling | Replace。 |
| NewLineOnAttributes |
false。 |
| OmitXmlDeclaration |
false。 |
| WriteEndDocumentOnClose |
true。 |