Back to the WFC main page
CXMLArchive
$Revision: 18 $
Description
This class handles serializing data (aka object persistence) to and
from XML documents. It is patterned after the MFC CArchive class.
Data Members
None.
Methods
BOOL GetAddNewLineAfterEachElement( void ) const
-
Returns TRUE if the class will add a new line after writing an
element to the document. This makes the resulting document easier to
read by humans.
BOOL IsLoading( void ) const
-
Returns TRUE if this object is being used to load
data from an XML document. This is set by calling ReadFrom().
BOOL IsStoring( void ) const
-
Returns TRUE if this object is being used to write
data to an XML document. This is set by calling WriteTo().
CExtensibleMarkupLanguageElement * Read( const CString& tag, BOOL& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, CString& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, CStringArray& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, CByteArray& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, CDWordArray& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, CFileTime& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, COleDateTime& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, COleDateTimeSpan& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, CSystemTime& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, CTime& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, CTimeSpan& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, double& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, DWORD& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, LONGLONG& value )
CExtensibleMarkupLanguageElement * Read( const CString& tag, ULONGLONG& value )
-
This method reads
value
from the XML document with the tag of tag
.
The data is read from children of the element passed in ReadFrom().
CByteArray values are automatically encoded using Base64.
CFileTime, CSystemTime,
and CTime values
are written in ISO8601 format. CTimeSpan values are written in seconds.
Read() will return a pointer to the
CExtensibleMarkupLanguageElement
object upon success or NULL on failure. If Read() fails,
value
will be set to an initial state.
void ReadFrom( CExtensibleMarkupLanguageElement * element_p )
-
Tells the object where to get its data from. Subsequent calls to Read()
will cause data to be read from the children of
element_p
.
void SetAddNewLineAfterEachElement( BOOL add_new_line = TRUE )
-
When you set this to TRUE, the object will add a line break after
writing an element. This results in an XML document that is slightly
larger but much easier to read by humans.
CExtensibleMarkupLanguageElement * Write( const CString& tag, BOOL value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const CByteArray& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const CDWordArray& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const CFileTime& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const COleDateTime& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const COleDateTimeSpan& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const CString& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const CStringArray& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const CSystemTime& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const CTime& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, const CTimeSpan& value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, double value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, DWORD value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, LONGLONG value )
CExtensibleMarkupLanguageElement * Write( const CString& tag, ULONGLONG value )
-
This method writes
value
to the XML document.
A new element is created with a tag name of tag
. The data
is written to this new element and the element is then made a child of
the element passed to WriteTo().
CByteArray will be Base64 encoded before being written to the document.
CFileTime,
CSystemTime,
COleDateTime, and CTime will be written in ISO8601 format. Only
CSystemTime will be written with a time
zone of Z. The other representations of time will have the time zone
offset information written.
CTimeSpan and COleDateTimeSpan will be written as total number of seconds.
void WriteTo( CExtensibleMarkupLanguageElement * element_p )
-
This tells the object where to write data. When data is written to
element_p
,
new elements are created and made children of element_p
.
Example
#include <wfc.h>
#pragma hdrstop
class CSimpleClass
{
protected:
CTime m_Birthday;
CString m_Name;
double m_PriceLimit;
public:
void Serialize( CXMLArchive& archive );
};
void CSimpleClass::Serialize( CXMLArchive& archive )
{
WFCTRACEINIT( TEXT( "CSimpleClass::Serialize()" ) );
CExtensibleMarkupLanguageElement * element_for_this_class = NULL;
CXMLArchive sub_archive;
if ( archive.IsStoring() )
{
element_for_this_class = archive.Write( TEXT( "CSIMPLECLASS" ), TEXT( "" ) );
sub_archive.WriteTo( element_for_this_class );
sub_archive.Write( TEXT( "BIRTHDAY" ), m_Birthday );
sub_archive.Write( TEXT( "NAME" ), m_Name );
sub_archive.Write( TEXT( "PRICE_LIMIT" ), m_PriceLimit );
}
else
{
element_for_this_class = archive.Read( TEXT( "CSIMPLECLASS" ), TEXT( "" ) );
sub_archive.ReadFrom( element_for_this_class );
sub_archive.Read( TEXT( "BIRTHDAY" ), m_Birthday );
sub_archive.Read( TEXT( "NAME" ), m_Name );
sub_archive.Read( TEXT( "PRICE_LIMIT" ), m_PriceLimit );
}
}
Copyright, 2000, Samuel R. Blackburn
$Workfile: CXMLArchive.cpp $
$Modtime: 1/17/00 9:24a $