Compact XML Infoset binary encoding using MC-NBFX?

Microsoft has implemented its own compact binary XML encoding (MC-NBFX), which is an option in WCF for transmitting XML info sets (e.g. SOAP requests and responses) more efficiently than standard XML text encodings.

I would like to use the same encoding for use in general, for example. to save a large XML file to disk in compact binary form.

I started with:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(@"<Foo><Bar>abc</Bar></Foo>");

using(FileStream fs = new FileStream("c:/tmp/foo.bin", FileMode.Create))
{
    using(XmlDictionaryWriter xbw = XmlDictionaryWriter.CreateBinaryWriter(fs))
    {
        xmlDoc.WriteTo(xbw);
    }
}

This actually outputs the MC-NBFX file, but if I encode an XML document with duplicate lines (for example, element names), these names appear several times in the binary file.

XmlDictionaryWriter , . , CreateBinaryWriter() / . , :

XmlDictionary xmlDictionary = new XmlDictionary();
xmlDictionary.Add("Foo");
xmlDictionary.Add("Bar");

using(XmlDictionaryWriter xbw = XmlDictionaryWriter.CreateBinaryWriter(fs, xmlDictionary))
{
    xmlDoc.WriteTo(xbw);
}

, , . (, , ) XmlBinaryWriterSession. :.

XmlBinaryWriterSession writerSession = new XmlBinaryWriterSession();
using(XmlDictionaryWriter xbw = XmlDictionaryWriter.CreateBinaryWriter(fs, null, writerSession))
{
    xmlDoc.WriteTo(xbw);
}

, , , XmlBinaryWriterSession . , XmlBinaryWriterSession, , , XML (MC-NBFX , , ).

. , , ?

.

+4

All Articles