//void CUpdateMgr::ParseXml(string xml) bool CUpdateMgr::ParseXml(string xml,ClientType nClientType,ParseType nParseType) { g_Logger.Debug(__FILE__,__LINE__,"ParseXml %s,ClientType = %d,ParseType=%d",xml.c_str(),nClientType,nParseType); bool bRet=true; TiXmlDocument doc;//( "demo.xml" ); switch(nParseType) { case PARSE_TYPE_FILE: { bRet = doc.LoadFile(xml); if (false == bRet) { g_Logger.Debug(__FILE__,__LINE__,"加载文件失败 %s",xml.c_str()); return bRet; } break; } case PARSE_TYPE_MEMORY: doc.Parse(xml.c_str()); break;; } //TiXmlElement xmlElement = doc.GetChar() TiXmlElement* rootElement = doc.RootElement(); //School元素 TiXmlElement* pElement = rootElement->ToElement(); TiXmlNode* pchild = rootElement->FirstChild(); switch(nClientType) { case SERVER: ParseServerXml(pElement); break; case LOCAL: ParseLocalXml(pchild); break; } }
kerberos::StringMap getSettingsFromXML(const std::string & path) { kerberos::StringMap settings; std::string directory = path.substr(0,path.rfind('/')) + "/" ; TiXmlDocument doc(path.c_str()); if(doc.LoadFile()) { TiXmlNode * root = doc.FirstChildElement("kerberos"); if(root) { root = root->FirstChildElement("instance"); TiXmlElement * node = root->FirstChildElement(); while (node) { settings[node->Value()] = node->ToElement()->GetText(); if(node->Attribute("file") != 0) { // read configuration file.. std::string path = directory + node->Attribute("file"); TiXmlDocument doc(path.c_str()); if(doc.LoadFile()) { TiXmlElement * subnode = doc.FirstChildElement(); getSettingsFromXML(subnode, subnode->Value(), settings); } } node = node->NextSiblingElement(); } } } else { throw TinyXMLOpenFileException(); } return settings; }
void getSettingsFromXML(TiXmlElement * root, std::string prefix, kerberos::StringMap & settings) { // First element is wrapper TiXmlElement * node = root->FirstChildElement(); while (node) { if(node->FirstChild()) { if(node->FirstChild()->Type()==TiXmlNode::TINYXML_TEXT) { settings[prefix + "." + node->Value()] = node->ToElement()->GetText(); } else { getSettingsFromXML(node, prefix + "." + node->Value(), settings); } } else { settings[prefix + "." + node->Value()] = ""; } node = node->NextSiblingElement(); } }