CXMLElement* CCollectionFile::CloneMetadata(CXMLElement* pMetadata) { CString strURI = pMetadata->GetAttributeValue( L"xmlns:s" ); if ( strURI.IsEmpty() ) return NULL; CXMLElement* pCore = pMetadata->GetFirstElement(); if ( pCore == NULL ) return NULL; if ( CSchemaPtr pSchema = SchemaCache.Get( strURI ) ) { pMetadata = pSchema->Instantiate(); } else { pMetadata = new CXMLElement( NULL, pCore->GetName() + 's' ); pMetadata->AddAttribute( CXMLAttribute::schemaName, strURI ); } pCore = pCore->Clone(); pMetadata->AddElement( pCore ); CString strName = pMetadata->GetName(); if ( _tcsnicmp( strName, L"s:", 2 ) == 0 ) pMetadata->SetName( strName.Mid( 2 ) ); strName = pCore->GetName(); if ( _tcsnicmp( strName, L"s:", 2 ) == 0 ) pCore->SetName( strName.Mid( 2 ) ); for ( POSITION pos = pCore->GetElementIterator(); pos; ) { CXMLNode* pNode = pCore->GetNextElement( pos ); CString strNodeName = pNode->GetName(); if ( _tcsnicmp( strNodeName, L"s:", 2 ) == 0 ) pNode->SetName( strNodeName.Mid( 2 ) ); } for ( POSITION pos = pCore->GetAttributeIterator(); pos; ) { CXMLNode* pNode = pCore->GetNextAttribute( pos ); CString strNodeName = pNode->GetName(); if ( _tcsnicmp( strNodeName, L"s:", 2 ) == 0 ) pNode->SetName( strNodeName.Mid( 2 ) ); } return pMetadata; }
CXMLElement* CXMLElement::Prefix(const CString& sPrefix, CXMLElement* pParent) const { CXMLElement* pCloned = Clone( pParent ); if ( pCloned ) { pCloned->SetName( sPrefix + pCloned->GetName() ); for ( POSITION pos = pCloned->GetElementIterator() ; pos ; ) { CXMLElement* pNode = pCloned->GetNextElement( pos ); pNode->SetName( sPrefix + pNode->GetName() ); } for ( POSITION pos = pCloned->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pNode = pCloned->GetNextAttribute( pos ); pNode->SetName( sPrefix + pNode->GetName() ); } } return pCloned; }