5/5 (8 avis)
Vue 7 293 fois - Téléchargée 1 515 fois
void CEnglish_GrammarDlg::OnBnClickedLoadxml() { CoInitialize(NULL); srand(time(NULL)); CXMLDOMDocument m_xmlEnglishDoc; CXMLDOMNode xmlWordBookNode; CXMLDOMNodeList xmlWordBookNodeList; CXMLDOMNode xmlWorkSheetNode1;//Faux Amis CXMLDOMNode xmlWorkSheetNode2;//Irregular Verbs CXMLDOMNodeList xmlRowNodeList; CString test = ""; if (!m_xmlEnglishDoc.CreateDispatch(_T("MSXML.DOMDocument"))) return; if(!m_xmlEnglishDoc.load(COleVariant(_T("ENGLISH (FAUX AMIS).xml")))) { AfxMessageBox(_T("ENGLISH (FAUX AMIS).xml NON EXISTENT\nOR ERROR INSIDE THE XML!!!!")); return; } xmlWordBookNode.AttachDispatch(m_xmlEnglishDoc.get_documentElement()); xmlWordBookNodeList.AttachDispatch(xmlWordBookNode.get_childNodes()); xmlWorkSheetNode1.AttachDispatch(xmlWordBookNodeList.get_item(0)); xmlRowNodeList.AttachDispatch(xmlWorkSheetNode1.get_childNodes()); m_iFauxAmisCount = xmlRowNodeList.get_length();//101 for (int i = 0; i < xmlRowNodeList.get_length(); i++) { CXMLDOMNodeList xmlCellNodeList; CXMLDOMNode xmlRowNode; CXMLDOMNode xmlDataNode; xmlRowNode.AttachDispatch(xmlRowNodeList.get_item(i)); if (xmlRowNode.get_baseName() == "Word") { xmlCellNodeList.AttachDispatch(xmlRowNode.get_childNodes()); xmlDataNode.AttachDispatch(xmlCellNodeList.get_item(0)); m_EnArray.push_back((LPCTSTR)xmlDataNode.get_text()); xmlDataNode.DetachDispatch(); xmlDataNode.AttachDispatch(xmlCellNodeList.get_item(1)); m_FrArray.push_back((LPCTSTR)xmlDataNode.get_text()); xmlDataNode.DetachDispatch(); } xmlRowNode.DetachDispatch(); xmlCellNodeList.DetachDispatch(); } xmlRowNodeList.DetachDispatch(); xmlWorkSheetNode2.AttachDispatch(xmlWordBookNodeList.get_item(1)); xmlRowNodeList.AttachDispatch(xmlWorkSheetNode2.get_childNodes()); m_iIrregularCount = xmlRowNodeList.get_length();//126 for (int i = 0; i < xmlRowNodeList.get_length(); i++) { CXMLDOMNodeList xmlCellNodeList; CXMLDOMNode xmlRowNode; CXMLDOMNode xmlDataNode; xmlRowNode.AttachDispatch(xmlRowNodeList.get_item(i)); if (xmlRowNode.get_baseName() == "Verb") { xmlCellNodeList.AttachDispatch(xmlRowNode.get_childNodes()); xmlDataNode.AttachDispatch(xmlCellNodeList.get_item(0)); m_InfArray.push_back((LPCTSTR)xmlDataNode.get_text()); xmlDataNode.DetachDispatch(); xmlDataNode.AttachDispatch(xmlCellNodeList.get_item(1)); m_SimplePastArray.push_back((LPCTSTR)xmlDataNode.get_text()); xmlDataNode.DetachDispatch(); xmlDataNode.AttachDispatch(xmlCellNodeList.get_item(2)); m_PpArray.push_back((LPCTSTR)xmlDataNode.get_text()); xmlDataNode.DetachDispatch(); xmlDataNode.AttachDispatch(xmlCellNodeList.get_item(3)); m_TranslArray.push_back((LPCTSTR)xmlDataNode.get_text()); xmlDataNode.DetachDispatch(); } xmlRowNode.DetachDispatch(); xmlCellNodeList.DetachDispatch(); } xmlRowNodeList.ReleaseDispatch(); xmlWorkSheetNode1.ReleaseDispatch(); xmlWorkSheetNode2.ReleaseDispatch(); xmlWordBookNodeList.ReleaseDispatch(); xmlWordBookNode.ReleaseDispatch(); m_xmlEnglishDoc.ReleaseDispatch(); GetDlgItem(IDC_NEXTWORD)->EnableWindow(TRUE); GetDlgItem(IDC_FAUXAMIS_TOCORRECT)->EnableWindow(TRUE); GetDlgItem(IDC_NEXTVERB)->EnableWindow(TRUE); GetDlgItem(IDC_IRREGULARVERB_TOCORRECT)->EnableWindow(TRUE); GetDlgItem(IDC_LOADXML)->EnableWindow(FALSE); m_iFauxAmisStartIndex = rand() % m_iFauxAmisCount; m_iIrregularStartIndex = rand() % m_iIrregularCount; CoUninitialize(); } void CEnglish_GrammarDlg::OnBnClickedNextword() { GetDlgItem(IDC_LABEL_FRENCH)->ShowWindow(SW_HIDE); GetDlgItem(IDC_EDITFRENCH)->SetWindowText(""); m_edEnglish.SetWindowText(m_EnArray[m_iFauxAmisStartIndex].c_str()); m_labFrench.SetWindowText(m_FrArray[m_iFauxAmisStartIndex].c_str()); m_iFauxAmisStartIndex = (++m_iFauxAmisStartIndex) % m_iFauxAmisCount; } void CEnglish_GrammarDlg::OnBnClickedFauxamisTocorrect() { GetDlgItem(IDC_LABEL_FRENCH)->ShowWindow(SW_SHOW); CString str = m_FrArray[(m_iFauxAmisStartIndex - 1) % m_iFauxAmisCount].c_str(); UpdateData(TRUE); if (str.CompareNoCase(m_strFrench) == 0) AfxMessageBox(_T("CORRECT")); } void CEnglish_GrammarDlg::OnBnClickedIrregularverbTocorrect() { GetDlgItem(IDC_LABEL_INFINITIVE)->ShowWindow(SW_SHOW); GetDlgItem(IDC_LABEL_SIMPLEPAST)->ShowWindow(SW_SHOW); GetDlgItem(IDC_LABEL_PP)->ShowWindow(SW_SHOW); GetDlgItem(IDC_LABEL_TRANSLATION)->ShowWindow(SW_SHOW); CString str1 = m_InfArray[(m_iIrregularStartIndex - 1) % m_iIrregularCount].c_str(); CString str2 = m_SimplePastArray[(m_iIrregularStartIndex - 1) % m_iIrregularCount].c_str(); CString str3 = m_PpArray[(m_iIrregularStartIndex - 1) % m_iIrregularCount].c_str(); CString str4 = m_TranslArray[(m_iIrregularStartIndex - 1) % m_iIrregularCount].c_str(); UpdateData(TRUE); CString strError = "ERRORS :\n"; if (str1.CompareNoCase(m_strInfinitive) != 0) strError += "- Infinitive\n"; if (str2.CompareNoCase(m_strSimplePast) != 0) strError += "- Simple past\n"; if (str3.CompareNoCase(m_strPP) != 0) strError += "- Past participle\n"; if (str4.CompareNoCase(m_strTranslation) != 0) strError += "- Translation\n"; if (strError == "ERRORS :\n") AfxMessageBox(_T("100% CORRECT")); else AfxMessageBox(strError); } void CEnglish_GrammarDlg::OnBnClickedNextverb() { GetDlgItem(IDC_LABEL_INFINITIVE)->ShowWindow(SW_HIDE); GetDlgItem(IDC_LABEL_SIMPLEPAST)->ShowWindow(SW_HIDE); GetDlgItem(IDC_LABEL_PP)->ShowWindow(SW_HIDE); GetDlgItem(IDC_LABEL_TRANSLATION)->ShowWindow(SW_HIDE); GetDlgItem(IDC_EDITINFINITIVE)->SetWindowText(""); GetDlgItem(IDC_EDITSIMPLEPAST)->SetWindowText(""); GetDlgItem(IDC_EDITPP)->SetWindowText(""); GetDlgItem(IDC_EDITTRANSLATION)->SetWindowText(""); int nEdit = rand() % 4; switch(nEdit) { case 0: m_edInfinitive.SetWindowText(m_InfArray[m_iIrregularStartIndex].c_str()); break; case 1: m_edSimplePast.SetWindowText(m_SimplePastArray[m_iIrregularStartIndex].c_str()); break; case 2: m_edPP.SetWindowText(m_PpArray[m_iIrregularStartIndex].c_str()); break; case 3: m_edTranslation.SetWindowText(m_TranslArray[m_iIrregularStartIndex].c_str()); break; } m_labInfinitive.SetWindowText(m_InfArray[m_iIrregularStartIndex].c_str()); m_labSimplePast.SetWindowText(m_SimplePastArray[m_iIrregularStartIndex].c_str()); m_labPP.SetWindowText(m_PpArray[m_iIrregularStartIndex].c_str()); m_labTranslation.SetWindowText(m_TranslArray[m_iIrregularStartIndex].c_str()); m_iIrregularStartIndex = (++m_iIrregularStartIndex) % m_iIrregularCount; }
5 nov. 2008 à 14:14
En effet, ce sera plus explicite! Mais c'est mon but sur le fait de permettre d'ajouter/supprimer des mots/verbes à l'aide du programme! Ce qui évitera aux users de lire le XML
4 nov. 2008 à 11:12
Bravo, mais il reste quelques defauts a ton XML :
- Tu continues a utiliser le tag "Cell" pour contenir plusieurs types d'informations, en te basant sur leur ordre pour connaitre leur signification.
Tu devrais plutot utiliser des tags plus explicites. Ex:
<Verb>
<Cell><Data>Do</Data></Cell>
<Cell><Data>Did</Data></Cell>
<Cell><Data>Done </Data></Cell>
<Cell><Data>Faire</Data></Cell>
</Verb>
serait mieux en:
<Verb>
Do
Did
Done
<traduction>Faire</traduction>
</Verb>
De meme, dans ton code tu utilises l'ordre des noeuds ce qui n'est pas tres conseille (mais c'est vrai que tu n'as pas le choix comme tu utilises toujours le meme noeud) :
xmlCellNodeList.AttachDispatch(xmlRowNode.get_childNodes());
xmlDataNode.AttachDispatch(xmlCellNodeList.get_item(0));
.../...
xmlDataNode.AttachDispatch(xmlCellNodeList.get_item(1));
Si ce qui t'arrete est le faite de devoir editer ton fichier a la main, je te conseille de faire rapidement un petit programme d'export qui convertirait ton format actuel au format desire (parce qu'a la main, tu vas te prendre la tete, et il y aura forcement une eerreur ou deux d'inattention...)
Bonne chance pour la suite, je l'attend avec impatience (lire ton fichier XML a deja fait beaucoup pour mon niveau d'anglais :o) )
1 nov. 2008 à 17:29
Je viens d'updater mon code, j'aurais pu le faire depuis le temps mais faute de paiement de ma connexion ...
L'amélioration c'est au niveau du XML mais je projette déjà de faire un programme pour pouvoir ajouter d'autres mots et verbes
7 oct. 2008 à 10:27
Meme si le logiciel sera plus complexe, c'est mieux et plus evolutif que d'implementer une methode de serialisation a la main.
Ce n'est pas pour rien que l'industrie utilise ce format.
7 oct. 2008 à 08:05
Pour ta remarque vidjidu91, je crois que l'idée d'un XML plus parlant est le mieux non?
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.