void XMLDocument::PutBoolean(TiXmlElement& parent, const string& szName, bool bValue) { TiXmlElement newelement(szName.c_str()); TiXmlText text(bValue? "true" : "false"); newelement.InsertEndChild(text); TiXmlElement* existing = parent.FirstChildElement(szName.c_str()); if(existing) parent.ReplaceChild(existing, newelement); else parent.InsertEndChild(newelement); }
void XMLDocument::PutString(TiXmlElement& parent, const string& szName, const string& szValue) { TiXmlElement newelement(szName.c_str()); TiXmlText text(szValue.c_str()); newelement.InsertEndChild(text); TiXmlElement* existing = parent.FirstChildElement(szName.c_str()); if(existing) parent.ReplaceChild(existing, newelement); else parent.InsertEndChild(newelement); }
void GpxTrkElement::SetSimpleExtension(const wxString &name, const wxString &value) { //FIXME: if the extensions don't exist, we should create them TiXmlElement * exts = FirstChildElement("extensions"); if (exts) { TiXmlElement * ext = exts->FirstChildElement(name.ToUTF8()); if (ext) exts->ReplaceChild(ext, GpxSimpleElement(name, value)); else exts->LinkEndChild(new GpxSimpleElement(name, value)); } }
// get the configuration file using hobbit protocol config void AgentBBWinUpdate::RunUpdate(std::string & configFile) { TiXmlDocument * update, * toUpdate; DeleteFile(m_bbwinupdateTmpFilePath.c_str()); m_mgr.Config(configFile.c_str(), m_bbwinupdateTmpFilePath.c_str()); update = new TiXmlDocument(m_bbwinupdateTmpFilePath.c_str()); bool loadUpdateOkay = update->LoadFile(); if ( !loadUpdateOkay ) { string err = (string)" failed to get the update " + configFile + (string)" or the update file is not correct"; m_mgr.ReportEventError(err.c_str()); } toUpdate = new TiXmlDocument(m_bbwinCfgTmpPath.c_str()); bool loadToUpdateOkay = toUpdate->LoadFile(); if ( !loadToUpdateOkay ) { delete update; string err = (string)" failed to open " + m_bbwinCfgTmpPath; m_mgr.ReportEventError(err.c_str()); } TiXmlElement *root = update->FirstChildElement( "configuration" ); TiXmlElement *toUpdateRoot = toUpdate->FirstChildElement( "configuration" ); if ( root && toUpdateRoot) { for (TiXmlNode * nameSpaceNode = root->FirstChild(); nameSpaceNode != NULL; nameSpaceNode = root->IterateChildren(nameSpaceNode)) { // we never update bbwin namespace (too dangerous) if (strcmp(nameSpaceNode->Value(), "bbwin") != 0) { TiXmlNode * destNameSpaceNode = toUpdateRoot->FirstChild(nameSpaceNode->Value()); if ( destNameSpaceNode ) { toUpdateRoot->ReplaceChild(destNameSpaceNode, *nameSpaceNode); } else { toUpdateRoot->InsertEndChild(*nameSpaceNode); } } else { string err = (string)" bbwin namespace update is not permitted. Please check the " + (string)configFile + (string)" on your hobbit server."; m_mgr.ReportEventError(err.c_str()); } } } if (toUpdate->SaveFile() != true) { string err = (string)" failed to save " + m_bbwinCfgTmpPath; m_mgr.ReportEventError(err.c_str()); } delete update; delete toUpdate; }