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.
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"); } } |
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.