Compartilhar via


IFragmentCapableXmlDictionaryWriter.WriteFragment Método

Definição

Grava um fragmento XML para o fluxo subjacente do gravador.

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)

Parâmetros

buffer
Byte[]

O buffer para o qual gravar.

offset
Int32

A posição inicial da qual gravar no buffer.

count
Int32

O número de bytes a serem gravados no buffer.

Exemplos

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  

Comentários

Grava um fragmento capturado entre StartFragment e EndFragment e chama de volta no fluxo principal do XmlDictionaryWriter. O fragmento escrito é count bytes que começam no índice offset do fornecido buffer. O comportamento será indefinido se o fragmento fornecido não tiver sido capturado usando essa instância de gravador.

Aplica-se a