XmlWriterSettings.CloseOutput 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,指出呼叫 XmlWriter 方法時,TextWriter 是否也應該關閉基礎資料流或 Close()。
public:
property bool CloseOutput { bool get(); void set(bool value); };
public bool CloseOutput { get; set; }
member this.CloseOutput : bool with get, set
Public Property CloseOutput As Boolean
屬性值
true
表示也關閉基礎資料流或 TextWriter,否則為 false
。 預設為 false
。
範例
下列範例會將 XML 片段寫入記憶體資料流程。
XmlWriterSettings settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.CloseOutput = false;
// Create the XmlWriter object and write some content.
MemoryStream strm = new MemoryStream();
XmlWriter writer = XmlWriter.Create(strm, settings);
writer.WriteElementString("orderID", "1-456-ab");
writer.WriteElementString("orderID", "2-36-00a");
writer.Flush();
writer.Close();
// Do additional processing on the stream.
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.OmitXmlDeclaration = true
settings.ConformanceLevel = ConformanceLevel.Fragment
settings.CloseOutput = false
' Create the XmlWriter object and write some content.
Dim strm as MemoryStream = new MemoryStream()
Dim writer As XmlWriter = XmlWriter.Create(strm, settings)
writer.WriteElementString("orderID", "1-456-ab")
writer.WriteElementString("orderID", "2-36-00a")
writer.Flush()
writer.Close()
' Do additional processing on the stream.
備註
當您想要將 XML 寫入資料流程時,此設定很有用,然後在 完成寫入之後 XmlWriter ,將額外的資訊新增至資料流程結尾。
此屬性只適用于 XmlWriter 輸出 XML 內容至資料流程或 TextWriter 的實例,否則會忽略此設定。