CreateBinaryWriter Method

XmlDictionaryWriter.CreateBinaryWriter Method

 

Creates an instance of XmlDictionaryWriter that writes WCF binary XML format.

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

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticCreateBinaryWriter(Stream)

Creates an instance of XmlDictionaryWriter that writes WCF binary XML format.

System_CAPS_pubmethodSystem_CAPS_staticCreateBinaryWriter(Stream, IXmlDictionary)

Creates an instance of XmlDictionaryWriter that writes WCF binary XML format.

System_CAPS_pubmethodSystem_CAPS_staticCreateBinaryWriter(Stream, IXmlDictionary, XmlBinaryWriterSession)

Creates an instance of XmlDictionaryWriter that writes WCF binary XML format.

System_CAPS_pubmethodSystem_CAPS_staticCreateBinaryWriter(Stream, IXmlDictionary, XmlBinaryWriterSession, Boolean)

Creates an instance of XmlDictionaryWriter that writes WCF binary XML format.

The binary format only supports one text node as the attribute value and therefore buffers the values written to it to emit a single node, as shown in the following sample code.

XmlWriter binarywriter = XmlDictionaryWriter.CreateBinaryWriter(Stream.Null);
binarywriter.WriteStartAttribute("StartAttribute");
string largeStr = new string('r', 100000);
for (int i = 0; i < 10000; i++) 
{
    binarywriter.WriteValue(largeStr);
}
binarywriter.WriteEndAttribute();

In the previous sample the code buffers about 1 GB of memory, while in the other writers it writes the values as they are provided.

Return to top
Show:
© 2016 Microsoft