Stingray® Foundation : Chapter 15 XML Serialization Architecture
Chapter 15 XML Serialization Architecture
Overview
MFC-application data can be serialized in XML format— using the high-level object model provided by the Stingray XML Serialization architecture. Programmers can easily insert and retrieve their application data structures (as elements) into and from the XML document. There is full support for multi-level nesting.
Because our architecture closely resembles MFC's serialization architecture, to plug any object into it all you need to do is implement an XMLSerialize() function in an IXMLSerialize() interface.
We provide default implementations for XML serializing MFC collection classes and GDI objects. We also provide a CDocument adapter class with built-in functionality for opening and saving XML documents. You start by overriding XMLSerialize() in your document class, just as you would with the MFC equivalent.
Use of the MSXML6 SDK
If you choose the XML features in Stingray Studio, then using the Stingray libraries on Microsoft Windows Vista or higher also requires using the MSXML6 SDK. As of Microsoft’s Windows Vista operating system, msxml.dll is no longer used. Msxml6.dll is used by default on Windows from Vista onwards.
The MSXML6 SDK is available at Microsoft’s Download Center at http://www.microsoft.com/downloads/details.aspx?FamilyID=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en.
Also, the default target NTDDI_VERSION should be defined as NTDDI_VISTA or higher in SupportedPlatforms.h in order for the libraries to use definitions for the MSXML6 interfaces. For more information, see “Using Visual Studio to Compile with an Older Platform Toolset.”
Usage Example
A sample implementation would look like this:
 
void CXMLSerArchiveDoc::XMLSerialize(SECXMLArchive& ar)
{
if(ar.IsStoring())
{
ar.Write("Intvalue", m_nIntMemb);
ar.OpenElement("ELEMENT11");
 
ar.Read("LONGVALUE", m_nLongMemb);
ar.OpenElement("ELEMENT12");
ar.Write("UNSIGNEDVALUE", (WORD)USHRT_MAX);
// Built-in support for collection classes in action:
// In this case m_myPtrArray is a CPtrArray containing
// reference to objects of type CMyObject.
ar.Write(NULL, CPtrArrayFTR<CMyObject, CMyObjectFTR>(m_myPtrArray));
ar.CloseElement("ELEMENT12");
 
 
ar.CloseElement("ELEMENT11");
}
 
else if(ar.IsLoading())
{
WORD w;
//Unwanted elements (eg. from obsolete versions can be ignored)
//eg. in this case m_nIntMemb written out is never retrieved.
 
ar.OpenElement("ELEMENT11");
ar.Read("LONGVALUE", m_nLongMemb);
ar.OpenElement(_T("ELEMENT12"));
ar.Read(_T("UNSIGNEDVALUE"), w);
ar.Read(NULL, CPtrArrayFTR<CMyObject, CMyObjectFTR>(m_myObject));
ar.CloseElement(_T("ELEMENT12"));
ar.CloseElement("ELEMENT11");
}
 
}