IFragmentCapableXmlDictionaryWriter.WriteFragment 方法

定义

将 XML 片段写入编写器的基础流。

public:
 void WriteFragment(cli::array <System::Byte> ^ buffer, int offset, int count);
public void WriteFragment (byte[] buffer, int offset, int count);
abstract member WriteFragment : byte[] * int * int -> unit
Public Sub WriteFragment (buffer As Byte(), offset As Integer, count As Integer)

参数

buffer
Byte[]

要写入的缓冲区。

offset
Int32

buffer 中开始写入数据的位置。

count
Int32

要写入 buffer 的字节数。

示例

MemoryStream stream = new MemoryStream();  
MemoryStream fragmentStream = new MemoryStream();  
XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream);  
IXmlFragmentCapableXmlDictionaryWriter fragmentWriter = writer as IXmlFragmentCapableXmlDictionaryWriter;  
if (fragmentWriter == null || !fragmentWriter.CanFragment)  
{  
Console.WriteLine("This writer doesn't support fragments");  
return;  
}  
writer.WriteStartElement("Root");  
fragmentWriter.StartFragment(fragmentStream, false);  
writer.WriteStartElement("Body");  
writer.WriteString("This is my body");  
writer.WriteEndElement();  
fragmentWriter.EndFragment();  
writer.WriteStartElement("CharsInTheBody");  
writer.WriteValue(fragmentStream.Length);  
writer.WriteEndElement();  
fragmentWriter.WriteFragment(fragmentStream.GetBuffer(), 0, (int)fragmentStream.Length);  
writer.WriteEndElement(); // Root  

注解

将捕获的片段写入到 StartFragmentEndFragment 之间并回调 XmlDictionaryWriter 的主流。 写入的片段为 count 字节,从提供的 offset 中的索引 buffer 处开始。 如果提供的片段不是使用此编写器实例捕获的,则行为是不确定的。

适用于