BOOL CProfiles::Setup() { Release(); CSingleLock pLock( &m_pSection, TRUE ); CString strXML; strXML = Settings.General.Path; int nLength = strXML.GetLength(); if ( nLength > 0 && strXML.GetAt(nLength-1) != '\\' ) strXML += '\\'; strXML += _T("xProfile.xml"); if ( CXMLElement* pXML = CXMLElement::FromFile( strXML, TRUE ) ) { CXMLElement* pXMLSub; if ( pXMLSub = pXML->GetElementByName( _T("Monitor") ) ) { m_pXMLMonitor = pXMLSub->Clone(); } delete pXML; return TRUE; } return FALSE; }
CXMLElement* CXMLElement::Clone(CXMLElement* pParent) const { CXMLElement* pClone = new CXMLElement( pParent, m_sName ); if ( ! pClone ) return NULL; // Out of memory for ( POSITION pos = GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute = GetNextAttribute( pos )->Clone( pClone ); if ( ! pAttribute ) return NULL; // Out of memory CString strNameLower( pAttribute->m_sName ); strNameLower.MakeLower(); // Delete the old attribute if one exists CXMLAttribute* pExisting; if ( pClone->m_pAttributes.Lookup( strNameLower, pExisting ) ) delete pExisting; pClone->m_pAttributes.SetAt( strNameLower, pAttribute ); if ( ! pClone->m_pAttributesInsertion.Find( strNameLower ) ) pClone->m_pAttributesInsertion.AddTail( strNameLower ); // Track output order workaround } for ( POSITION pos = GetElementIterator() ; pos ; ) { CXMLElement* pElement = GetNextElement( pos ); pClone->m_pElements.AddTail( pElement->Clone( pClone ) ); } ASSERT( ! pClone->m_sName.IsEmpty() ); pClone->m_sValue = m_sValue; return pClone; }
BOOL CBitziDownloader::MergeMetaData(CXMLElement* pOutput, CXMLElement* pInput) { if ( ! pOutput || ! pInput ) return FALSE; pOutput = pOutput->GetFirstElement(); if ( ! pOutput || pOutput->GetName() != pInput->GetName() ) return FALSE; for ( POSITION pos = pInput->GetElementIterator() ; pos ; ) { CXMLElement* pElement = pInput->GetNextElement( pos ); CXMLElement* pTarget = pOutput->GetElementByName( pElement->GetName() ); if ( pTarget == NULL ) pOutput->AddElement( pElement->Clone() ); } for ( POSITION pos = pInput->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute = pInput->GetNextAttribute( pos ); CXMLAttribute* pTarget = pOutput->GetAttribute( pAttribute->GetName() ); if ( pTarget == NULL ) pOutput->AddAttribute( pAttribute->Clone() ); } return TRUE; }
BOOL CXMLElement::Merge(const CXMLElement* pInput, BOOL bOverwrite) { if ( ! this || ! pInput ) return FALSE; if ( this == pInput ) return TRUE; if ( m_sName.CompareNoCase( pInput->m_sName ) != 0 ) return FALSE; TRACE( "Merging XML:%sand XML:%s", (LPCSTR)CT2A( ToString( FALSE, TRUE ) ), (LPCSTR)CT2A( pInput->ToString( FALSE, TRUE ) ) ); BOOL bChanged = FALSE; for ( POSITION pos = pInput->GetElementIterator() ; pos ; ) { CXMLElement* pElement = pInput->GetNextElement( pos ); CXMLElement* pTarget = GetElementByName( pElement->m_sName ); if ( pTarget == NULL ) { AddElement( pElement->Clone() ); bChanged = TRUE; } else if ( pTarget->Merge( pElement, bOverwrite ) ) { bChanged = TRUE; } } for ( POSITION pos = pInput->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute = pInput->GetNextAttribute( pos ); CXMLAttribute* pTarget = GetAttribute( pAttribute->m_sName ); if ( pTarget == NULL ) { AddAttribute( pAttribute->Clone() ); bChanged = TRUE; } else if ( bOverwrite && ! pTarget->Equals( pAttribute ) ) { pTarget->SetValue( pAttribute->GetValue() ); bChanged = TRUE; } } if ( bChanged ) TRACE( "resulting XML:%s\n", (LPCSTR)CT2A( ToString( FALSE, TRUE ) ) ); else TRACE( "resulting XML unchanged.\n" ); return bChanged; }
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; }
void CPlayProfilePage::OnAdd() { int nItem = m_wndList.GetNextItem( -1, LVNI_SELECTED ); CXMLElement* pXML = ( nItem != -1 ) ? (CXMLElement*)m_wndList.GetItemData(nItem) : NULL; if ( pXML ) pXML = pXML->Clone(); else pXML = new CXMLElement( NULL, _T("Album") ); if ( pXML = m_pXML->AddElement( pXML ) ) { CString strValue; m_wndClass.GetWindowText( strValue ); pXML->SetName( strValue.CompareNoCase("子类") == 0 ? _T("Album") : _T("Play") ); m_wndKey.GetWindowText( strValue ); pXML->AddAttribute( _T("ID"), strValue ); int nItem = m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM, m_wndList.GetItemCount(), strValue, 0, 0, pXML->IsNamed( "Album" ) ? 23 : 24, (LPARAM)pXML ); m_wndName.GetWindowText( strValue ); pXML->AddAttribute( _T("Play"), strValue ); m_wndList.SetItemText( nItem, 1, strValue ); m_wndClass.GetWindowText( strValue ); pXML->AddAttribute( _T("Class"), strValue ); m_wndHost.GetWindowText( strValue ); pXML->AddAttribute( _T("Host"), strValue ); m_wndList.SetItemText( nItem, 2, strValue ); m_wndAdmin.GetWindowText( strValue ); pXML->AddAttribute( _T("Admin"), strValue ); m_wndGroup.GetWindowText( strValue ); pXML->AddAttribute( _T("Group"), strValue ); } }