bool CI18N::SetLanguage(const std::string& strLanguageXMLPath) { BP_RUN_LOG_INF("load language xml failed","strLanguageXMLPath %s", strLanguageXMLPath.c_str()); CXml xml; if (!xml.Load(strLanguageXMLPath.c_str(), TIXML_ENCODING_UTF8)) { //表示加载资源XML不成功 BP_RUN_LOG_ERR(IVS_FAIL,"load language xml failed","NA"); return false; } //如果加载成功了,就遍历xml将所有的资源和语言绑定并加入map表 if (!xml.FindElemEx("Content")) { //没找到第一个结点 return false; } //先进行清除 Clear(); do { // 获取当前结点 const char* ResourceNode = xml.GetElem(); // 获取当前结点的值 const char* ResourceNodeValue = xml.GetElemValue(); // 转换编码,防止乱码 char* xml2ANSI = CToolsHelp::UTF8ToANSI(ResourceNodeValue); //把结点和值绑定进行插入 (void)VOS_MutexLock(m_pMutexLock); (void)m_mapResource2Language.insert(std::make_pair(ResourceNode, xml2ANSI)); (void)VOS_MutexUnlock(m_pMutexLock); free(xml2ANSI); } while (xml.NextElem()); return true; }
shared_ptr<PsiScale> CTestManager::LoadPsiScale(const CString& file_path) { CXml xml; if (!xml.Load(file_path)) return shared_ptr<PsiScale>(); auto scale = shared_ptr<PsiScale>(new PsiScale); scale->SetId(xml.GetIntegerAttrib(XML_ID)); scale->SetName(xml.GetAttrib(XML_NAME)); scale->SetDescription(xml.GetAttrib(XML_DESCRIPTION)); auto prologue_element = xml.GetElement(XML_PROLOGUE); if (prologue_element == nullptr) return shared_ptr<PsiScale>(); scale->SetPrologue(prologue_element->GetAttrib(XML_TEXT)); auto groups_element = xml.GetElement(XML_GROUPS); if (groups_element == nullptr) return shared_ptr<PsiScale>(); auto& group_items = groups_element->GetChildElements(); for (auto item : group_items) { PsiScaleGroup group; group.id = item->GetIntegerAttrib(XML_ID); group.description = item->GetAttrib(XML_DESCRIPTION); scale->AddGroup(group); } bool same_choices = xml.GetBoolAttrib(XML_SAME_CHOICES); if (same_choices) { auto choices_element = xml.GetElement(XML_CHOICES); if (choices_element == nullptr) return shared_ptr<PsiScale>(); for (auto item : choices_element->GetChildElements()) { QuestionChoice choice; choice.id = item->GetIntegerAttrib(XML_ID); choice.text = item->GetAttrib(XML_TEXT); scale->Choices().push_back(choice); } } auto questions_element = xml.GetElement(XML_QUESTIONS); if (questions_element == nullptr) return shared_ptr<PsiScale>(); auto& question_items = questions_element->GetChildElements(); for (auto item : question_items) { PsiScaleQuestion question(item->GetIntegerAttrib(XML_ID), item->GetAttrib(XML_TEXT), item->GetBoolAttrib(XML_REVERSE_SCORE), item->GetIntegerAttrib(XML_GROUP_ID)); scale->AddQuestion(question); } return scale; }
bool CPsiScale::Load(const CString& file_path) { CXml xml; if (!xml.Load(file_path)) return false; Reset(); _id = xml.GetIntegerAttrib(XML_ID); _name = xml.GetAttrib(XML_NAME); _description = xml.GetAttrib(XML_DESCRIPTION); _prologue = xml.GetElementData(XML_PROLOGUE); auto groups_element = xml.GetElement(XML_GROUPS); if (groups_element == nullptr) return false; auto& group_items = groups_element->GetChildElements(); for (auto item : group_items) { _groups.push_back(item->GetData()); } _same_choice = xml.GetBoolAttrib(XML_SAME_CHOICES); if (_same_choice) { auto choices_element = xml.GetElement(XML_CHOICES); if (choices_element == nullptr) return false; for (auto item : choices_element->GetChildElements()) { CQuestionChoice choice; choice.id = item->GetIntegerAttrib(XML_ID); choice.text = item->GetData(); _choices.push_back(choice); } } auto questions_element = xml.GetElement(XML_QUESTIONS); if (questions_element == nullptr) return false; for (auto question_item : questions_element->GetChildElements()) { if (_same_choice) { CPsiScaleQuestion question(question_item->GetIntegerAttrib(XML_ID), question_item->GetData(), question_item->GetBoolAttrib(XML_REVERSE_SCORE), question_item->GetAttrib(XML_SUB_SCALE)); _questions.push_back(question); } else { CPsiScaleQuestion question(question_item->GetIntegerAttrib(XML_ID), question_item->GetElementData(XML_TEXT), question_item->GetBoolAttrib(XML_REVERSE_SCORE), question_item->GetAttrib(XML_SUB_SCALE)); auto choices_element = question_item->GetElement(XML_CHOICES); if (choices_element == nullptr) return false; for (auto choice_item : choices_element->GetChildElements()) { CQuestionChoice choice; choice.id = choice_item->GetIntegerAttrib(XML_ID); choice.text = choice_item->GetData(); question.Choices().push_back(choice); } _questions.push_back(question); } } return true; }