Ejemplo n.º 1
0
void CXMLElement::Serialize(CArchive& ar)
{
	CXMLNode::Serialize( ar );

	if ( ar.IsStoring() )
	{
		ar.WriteCount( GetAttributeCount() );

		for ( POSITION pos = GetAttributeIterator() ; pos ; )
		{
			GetNextAttribute( pos )->Serialize( ar );
		}

		ar.WriteCount( GetElementCount() );

		for ( POSITION pos = GetElementIterator() ; pos ; )
		{
			GetNextElement( pos )->Serialize( ar );
		}
	}
	else // Loading
	{
		for ( int nCount = (int)ar.ReadCount() ; nCount > 0 ; nCount-- )
		{
			CXMLAttribute* pAttribute = new CXMLAttribute( this );
			pAttribute->Serialize( ar );

			// Skip attribute if name is missing
			if ( pAttribute->m_sName.IsEmpty() )
			{
				delete pAttribute;
				continue;
			}

			CString strNameLower( pAttribute->m_sName );
			strNameLower.MakeLower();

			// Delete the old attribute if one exists
			CXMLAttribute* pExisting;
			if ( m_pAttributes.Lookup( strNameLower, pExisting ) )
				delete pExisting;

			m_pAttributes.SetAt( strNameLower, pAttribute );

			if ( ! m_pAttributesInsertion.Find( strNameLower ) )
				m_pAttributesInsertion.AddTail( strNameLower );		// Track output order workaround
		}

		for ( int nCount = (int)ar.ReadCount() ; nCount > 0 ; nCount-- )
		{
			CXMLElement* pElement = new CXMLElement( this );
			pElement->Serialize( ar );
			m_pElements.AddTail( pElement );
		}
	}
}