XmlWriterSettings.CloseOutput 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示调用 Close() 方法时 XmlWriter 是否也应关闭基础流或 TextWriter。
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
属性值
如果还应该关闭该基础流或 TextWriter,则为 true
;否则,为 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否则,将忽略此设置。