Applied Informatics FastInfoset Library

FastInfoset User Guide

Contents

Introduction

Fast Infoset specifies a standardized (ITU-T Rec. X.891 and ISO/IEC 24824-1) binary encoding for the XML Information Set. An XML infoset (such as a DOM tree or SAX events in programmatic representations) may be serialized to an XML 1.x document or, as specified by the Fast Infoset standard, may be serialized to a fast infoset document. Fast infoset documents are generally smaller in size and faster to parse and serialize than equivalent XML documents. This is especially important if such documents are to be sent over a network.

More information on Fast Infoset can be found here and here.

Applied Informatics' implementation of Fast Infoset based on POCO is integrated with the POCO XML classes. Anyone familiar with the POCO XML classes can immediately start to work with the Applied Informatics Fast Infoset implementation.

Usage

Writing of Fast Infoset Files

#include "Poco/FastInfoset/FastInfosetWriter.h"

[...]

std::ostringstream out(std::ios::binary); // must use binary output streams!
Poco::FastInfoset::FastInfosetWriter w(out);
w.startDocument();
w.startElement("some:uri:here", "myelement", "");
w.endElement("some:uri:here", "myelement", "");
// should be able to compress this one
w.startElement("some:uri:here", "myelement", "");
w.endElement("some:uri:here", "myelement", "");
w.endDocument();

Reading of Fast Infoset Files

The following example opens the file test.finf, parses it and sends the decompressed data to the Poco::XML::ContentHandler of type MyContentHandler:

#include "Poco/FastInfoset/FastInfosetWriter.h"

[...]

class MyContentHandler: public Poco::XML::ContentHandler
{
    [...]

    void startDocument() { ... }
    void endDocument() { ... }
    void startElement(  const Poco::XML::XMLString& uri, 
                        const Poco::XML::XMLString& localName, 
                        const Poco::XML::XMLString& qname, 
                        const Poco::XML::Attributes& attrList) 
    { 
        [...]
    }

    void endElement(const Poco::XML::XMLString& uri, 
                    const Poco::XML::XMLString& localName, 
                    const Poco::XML::XMLString& qname) 
    { 
        [...]
    }

    [...]
};

[...]

std::ifstream input;
input.open("test.finf", std::ios::binary);
MyContentHandler handler;
Poco::FastInfoset::FastInfosetParser parser;

parser.setContentHandler(&handler);

Poco::XML::InputSource is(input);
parser.parse(&is);

Converting from Fast Infoset to XML and back

To simply convert a Fast Infoset file into an XML file or vice versa, the Poco::FastInfoset::Utility class can be used:

#include "Poco/FastInfoset/Utility.h"

std::ifstream input;
input.open("test.xml", std::ios::binary);
std::ofstream output;
output.open("test.finf", std::ios::binary);
Utility::convertToFIS(input, output);

#include "Poco/FastInfoset/Utility.h"

std::ifstream input;
input.open("test.finf", std::ios::binary);
std::ofstream output;
output.open("test.xml", std::ios::binary);
Utility::convertToXML(input, output);

Building a DOM Tree from a Fast Infoset Document

FastInfosetParser parser;
DOMBuilder domBuilder(parser);
AutoPtr<Document> pDoc = domBuilder.parse("sample.fis");