Export (0) Print
Expand All

IFragmentCapableXmlDictionaryWriter.WriteFragment Method

Writes an XML fragment to the underlying stream of the writer.

Namespace:  System.Xml
Assembly:  System.Runtime.Serialization (in System.Runtime.Serialization.dll)

void WriteFragment(
	byte[] buffer,
	int offset,
	int count
)

Parameters

buffer
Type: System.Byte[]

The buffer to write to.

offset
Type: System.Int32

The starting position from which to write in buffer.

count
Type: System.Int32

The number of bytes to be written to the buffer.

Writes a fragment captured between StartFragment and EndFragment and calls back into the XmlDictionaryWriter's main stream. The fragment written is count bytes starting at the index offset from the supplied buffer. The behavior is undefined if the supplied fragment was not captured using this writer instance.

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft