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
)
void WriteFragment (
	byte[] buffer, 
	int offset, 
	int count
)
function WriteFragment (
	buffer : byte[], 
	offset : int, 
	count : int
)
Not applicable.

Parameters

buffer

The buffer to write to.

offset

The starting position from which to write in buffer.

count

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft