How do I use Fast Infoset Documents?

Problem

You may need to accept or distribute XML documents encoded as Fast Infoset.

Resolution

Liquid XML support the Fast Infoset binary standard for C++, C# and VB .Net. Not only can FI documents can be read in and written out, but you can also read in an FI document and write out an XML document and visa-versa. This makes Liquid XML an excellent data conversion tool.

Serialization

FI documents can be read in the same manner as xml documents using the FromXml methods. Liquid XML identifies FI documents and parses them accordingly. Writing FI documents requires the use of the ToFastInfoset methods.

Example

  C++

// read in Fast Infoset document...
CQuoteRequestPtr elm = CQuoteRequest::CreateInstance();
elm->FromXmlFile("c:\\MyFastInfosetFile.finf");

// write out Fast Infoset document...
elm->ToFastInfosetFile("c:\\MyFastInfosetFile.finf");

  C#

// read in Fast Infoset document...
QuoteRequest elm = new QuoteRequest();
elm.FromXmlFile(@"c:\MyFastInfosetFile.finf");

// write out Fast Infoset document...
elm.ToFastInfosetFile(@"c:\MyFastInfosetFile.finf");

Generate Fast Infoset Tables in C++

Note: this is an optional feature provided in the Output options screen in the Wizard.

The FI standard specifies that an FI document to use external vocabulary tables. This has the advantage of producing smaller FI documents that do not contain the vocabulary. Liquid XML takes this one step further by allowing the external vocabulary tables to be generated directly into your binding library code. Essentially this means your external vocabulary is contained as internal tables within your code. These tables are built as static data that is only created once at application start up time, and has the dual advantage of reducing parsing time as well as reducing document size.

Important Note: the generated FI documents will now only be interpretid by the exact version of the library that created them. This option should not be used if interoperable with other vendors' FI implementations.

In order to use the generated tables, and hence omit vocabulary content from FI documents, you must set a flag within the FIContext.

Example

    C++

// set the UseGeneratedVocabulary flag within the default serialization context
LtXmlLib16::CXmlSerializationContext& context = LtXmlLib16::CXmlSerializationContext::GetDefaultContext();
context.GetFIContext().SetUseGeneratedVocabulary(true);

As the generated tables are derived from the schema, they only contain element and attribute tag values and do not contain data values. You may also want to extend the default tables with additional data such as known recurring data. E.g. if you have a personal data, you may wish to add common surnames.

You can do this using the AddElementValue and AddAttributeValue CFIVocabulary methods within the PopulateFITables method of the generated class CAppLifetime in the Enumerations.cpp file of your generated library.

The following Example shows common surname values added within the HAND CODED BLOCK after the generated values:

    C++

// Populate internal Fast Infoset tables
static void PopulateFITables(LtXmlLib16::CFIVocabulary& vocabulary)
{
    vocabulary.AddElement(_T(""), _T(""), _T("Item"));
    vocabulary.AddElement(_T(""), _T(""), _T("Description"));
    vocabulary.AddElement(_T(""), _T(""), _T("Quantity"));
    vocabulary.AddElement(_T(""), _T(""), _T("QuoteRequest"));
    vocabulary.AddAttribute(_T(""), _T(""), _T("Priority"));
    vocabulary.AddAttribute(_T(""), _T(""), _T("International"));
    vocabulary.AddAttribute(_T(""), _T(""), _T("PriceZone"));
    vocabulary.AddAttribute(_T(""), _T(""), _T("QID"));
    vocabulary.AddElement(_T(""), _T(""), _T("CustomerID"));
    vocabulary.AddElement(_T(""), _T(""), _T("QuoteResponse"));
    vocabulary.AddElement(_T(""), _T(""), _T("QuoteID"));
    vocabulary.AddElement(_T(""), _T(""), _T("ValidTo"));
    vocabulary.AddElement(_T(""), _T(""), _T("QuotedItem"));
    vocabulary.AddElement(_T(""), _T(""), _T("PricePerItemInPence"));
    vocabulary.AddElement(_T(""), _T(""), _T("CurrentAvalibility"));
    
    // ##HAND_CODED_BLOCK_START ID="FI Table Declarations"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    // Add Common Attribute and Element values here...
    // vocabulary.AddAttributeValue("Value");
    // vocabulary.AddElementValue("Value");
    vocabulary.AddElementValue("Jones");
    vocabulary.AddElementValue("Smith");
    // ##HAND_CODED_BLOCK_END ID="FI Table Declarations"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS

 

Notes

Description Value
Article Created 20/4/2007
Version Liquid XML 2006 and greater