Objective Chart : PART II Programmer’s Guide : Chapter 27 XML Serialization Architecture : Usage
Usage
Adding XML serialization capability to an existing Objective Chart application is a very simple process:
1. Modify your document class to derive from the SFL SECXMLDocAdapter_T template class, using the document's existing base class as the template parameter.
2. Edit the application's resource script and add suitable menu entries for the XML Open/Save commands. Now update the document's message map and add the mapping macros that connect these new commands with the pre-built command-handlers provided by the SECXMLDocAdapter_T class.
 
BEGIN_MESSAGE_MAP(CSimpleCustomDoc, CGraphDoc)
//{{AFX_MSG_MAP(CSimpleCustomDoc)
ON_COMMAND(ID_FILE_OPENXML, OnSECFileOpenXML)
ON_COMMAND(ID_FILE_SAVEXML, OnSECFileSaveXML)
ON_COMMAND(ID_FILE_SAVEXMLAS, OnSECFileSaveXMLAs)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
3. Provide an implementation for the IXMLSerialize methods that the document inherits through the document adapter base. The IXMLSerialize::GetElementType() routine returns the XML descriptor tag for the document while the IXMLSerialize::XMLSerialize() virtual serves as the serialization framework's entry point into the Objective Chart XML formatter hierarchy.
virtual void GetElementType(LPTSTR lpStr)
{
ASSERT(lpStr != NULL);
_tcscpy(lpStr, _T("CSimpleCustomDoc"));
}
 
void CSimpleCustomDoc::XMLSerialize(SECXMLArchive& ar)
{
SRGraph* pGraph = &m_Graph;
if(ar.IsStoring())
ar.Write( _T("Graph"), SRGraphFTR(pGraph));
else
ar.Read(_T("Graph"), SRGraphFTR(pGraph));
}