TiXmlElement* SaveJobsXML(TiXmlElement* pRoot, int buildingQualities[]) { TiXmlElement* pJobs = new TiXmlElement("Jobs"); pRoot->LinkEndChild(pJobs); for (int i = 0; i < NUMJOBTYPES; i++) { TiXmlElement* pJob = new TiXmlElement(XMLifyString(g_Brothels.m_JobManager.JobName[i])); pJobs->LinkEndChild(pJob); pJob->SetAttribute("Qual", buildingQualities[i]); } return pJobs; }
void GpxWptElement::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)); } }
bool CBookmarksDialog::AddBookmark(const wxString &name, const wxString &local_dir, const CServerPath &remote_dir, bool sync) { if (local_dir.empty() && remote_dir.empty()) return false; if ((local_dir.empty() || remote_dir.empty()) && sync) return false; CInterProcessMutex mutex(MUTEX_GLOBALBOOKMARKS); CXmlFile file(wxGetApp().GetSettingsFile(_T("bookmarks"))); TiXmlElement* pDocument = file.Load(); if (!pDocument) { wxString msg = file.GetError() + _T("\n\n") + _("The bookmark could not be added."); wxMessageBoxEx(msg, _("Error loading xml file"), wxICON_ERROR); return false; } TiXmlElement *pInsertBefore = 0; TiXmlElement *pBookmark; for (pBookmark = pDocument->FirstChildElement("Bookmark"); pBookmark; pBookmark = pBookmark->NextSiblingElement("Bookmark")) { wxString remote_dir_raw; wxString old_name = GetTextElement(pBookmark, "Name"); if (!name.CmpNoCase(old_name)) { wxMessageBoxEx(_("Name of bookmark already exists."), _("New bookmark"), wxICON_EXCLAMATION); return false; } if (name < old_name && !pInsertBefore) pInsertBefore = pBookmark; } if (pInsertBefore) pBookmark = pDocument->InsertBeforeChild(pInsertBefore, TiXmlElement("Bookmark"))->ToElement(); else pBookmark = pDocument->LinkEndChild(new TiXmlElement("Bookmark"))->ToElement(); AddTextElement(pBookmark, "Name", name); if (!local_dir.empty()) AddTextElement(pBookmark, "LocalDir", local_dir); if (!remote_dir.empty()) AddTextElement(pBookmark, "RemoteDir", remote_dir.GetSafePath()); if (sync) AddTextElementRaw(pBookmark, "SyncBrowsing", "1"); if (!file.Save(false)) { wxString msg = wxString::Format(_("Could not write \"%s\", the bookmark could not be added: %s"), file.GetFileName(), file.GetError()); wxMessageBoxEx(msg, _("Error writing xml file"), wxICON_ERROR); return false; } return true; }
TiXmlElement* GeneticAddSpawnpointAction::toXmlElement() { TiXmlElement* element; element = new TiXmlElement("AddSpawnpointAction"); element->SetAttribute("Active",(int)active); element->SetAttribute("Symetric",(int)symetric); TiXmlElement* element2 = new TiXmlElement("Spawnpoint"); Bodypart::spawnpointToXmlElement(sp,element2); element->LinkEndChild(element2); return element; };
/** * Creates a mesh object in the XML structure. **/ void IO::saveMesh(TiXmlElement *parent, Mesh *m) { vector<Vertex *> *vertices = m->getVertices(); vector<Face *> *faces = m->getFaces(); if (vertices->empty() && faces->empty()) return; TiXmlElement *meshXML = new TiXmlElement("mesh"); parent->LinkEndChild(meshXML); if (!vertices->empty()) { TiXmlElement *vertXML = new TiXmlElement("vertices"); meshXML->LinkEndChild(vertXML); unsigned n = vertices->size(); for (unsigned i = 0; i < n; i++) { Vertex *v = (*vertices)[i]; TiXmlElement *vertex = new TiXmlElement("vertex"); vertex->SetDoubleAttribute("x", v->coord.x); vertex->SetDoubleAttribute("y", v->coord.y); vertex->SetDoubleAttribute("u", v->texCoord.x); vertex->SetDoubleAttribute("v", v->texCoord.y); vertex->SetAttribute("selected", v->selected); vertXML->LinkEndChild(vertex); } } if (!faces->empty()) { TiXmlElement *facesXML = new TiXmlElement("faces"); meshXML->LinkEndChild(facesXML); saveFaces(facesXML, faces, vertices); } }
TiXmlElement *cpSpaceSerializer::createBodyElm(cpBody *body) { TiXmlElement *elm = new TiXmlElement("body"); CPSS_ID id; if (delegate) { id = delegate->makeId(body); delegate->writing(body, id); } else id = CPSS_DEFAULT_MAKE_ID(body); BodyMap::iterator itr = _bodyMap.find(id); //It hasn't been written yet, so write it, but not the staticBody if (itr == _bodyMap.end() && body != _space->staticBody) { elm->LinkEndChild(createValueElm("id", id)); elm->LinkEndChild(createValueElm("mass", body->m)); elm->LinkEndChild(createValueElm("inertia", body->i)); elm->LinkEndChild(createPointElm("p", body->p)); elm->LinkEndChild(createPointElm("v", body->v)); elm->LinkEndChild(createPointElm("f", body->f)); elm->LinkEndChild(createValueElm("a", body->a)); elm->LinkEndChild(createValueElm("w", body->w)); elm->LinkEndChild(createValueElm("t", body->t)); _bodyMap[id] = body; } return elm; }
bool AddXmlFile(string& szFileName, int& m_ID, sockaddr_in& m_sockaddr) { string m_ip = inet_ntoa(m_sockaddr.sin_addr); string m_id = itos(m_ID); string m_port = itos(ntohs(m_sockaddr.sin_port)); CString appPath = GetAppPath(); string seperator = "\\"; string fullPath = appPath.GetBuffer(0) + seperator+szFileName; m_file(fullPath); TiXmlDocument *myDocument = new TiXmlDocument(fullPath.c_str()); myDocument->LoadFile(); TiXmlElement *RootElement = myDocument->RootElement(); //创建一个元素并连接。 TiXmlElement *server = new TiXmlElement("Server"); //设置元素的属性。 server->SetAttribute("ID", m_id.c_str()); //创建ip子元素、port子元素并连接。 RootElement->LinkEndChild(server); //创建ip子元素、port子元素并连接。 TiXmlElement *ip = new TiXmlElement("ip"); TiXmlElement *port = new TiXmlElement("port"); server->LinkEndChild(ip); server->LinkEndChild(port); //设置ip子元素和port子元素的内容并连接。 TiXmlText *ipContent = new TiXmlText(m_ip.c_str()); TiXmlText *portContent = new TiXmlText(m_port.c_str()); ip->LinkEndChild(ipContent); port->LinkEndChild(portContent); //RootElement->InsertEndChild(*server); myDocument->SaveFile(fullPath.c_str());//保存到文件 return true; }
void CConnectRemoteMachineWindow::saveHistory() { //创建一个XML的文档对象。 TiXmlDocument *pDocument = new TiXmlDocument(); int i = 0; std::deque<CString>::iterator iter = m_historyCommand.begin(); TiXmlElement *rootElement = new TiXmlElement("root"); pDocument->LinkEndChild(rootElement); for(; iter != m_historyCommand.end(); iter++) { char key[256] = {0}; kbe_snprintf(key, 256, "item%d", i++); TiXmlElement *rootElementChild = new TiXmlElement(key); rootElement->LinkEndChild(rootElementChild); char buffer[4096] = {0}; CString strCommand = (*iter); int len = WideCharToMultiByte(CP_ACP, 0, strCommand, strCommand.GetLength(), NULL, 0, NULL, NULL); WideCharToMultiByte(CP_ACP,0, strCommand, strCommand.GetLength(), buffer, len, NULL, NULL); buffer[len + 1] = '\0'; TiXmlText *content = new TiXmlText(buffer); rootElementChild->LinkEndChild(content); } CString appPath = GetAppPath(); CString fullPath = appPath + L"\\histroycommands1.xml"; char fname[4096] = {0}; int len = WideCharToMultiByte(CP_ACP, 0, fullPath, fullPath.GetLength(), NULL, 0, NULL, NULL); WideCharToMultiByte(CP_ACP,0, fullPath, fullPath.GetLength(), fname, len, NULL, NULL); fname[len + 1] = '\0'; pDocument->SaveFile(fname); }
void CStartServerWindow::saveLayouts() { //创建一个XML的文档对象。 TiXmlDocument *pDocument = new TiXmlDocument(); int i = 0; KBEUnordered_map< std::string, std::vector<LAYOUT_ITEM> >::iterator iter = layouts_.begin(); TiXmlElement *rootElement = new TiXmlElement("root"); pDocument->LinkEndChild(rootElement); for(; iter != layouts_.end(); iter++) { std::vector<LAYOUT_ITEM>::iterator iter1 = iter->second.begin(); TiXmlElement *rootElementChild = new TiXmlElement(iter->first.c_str()); rootElement->LinkEndChild(rootElementChild); for(; iter1 != iter->second.end(); iter1++) { LAYOUT_ITEM& item = (*iter1); TiXmlElement *rootElementChild1 = new TiXmlElement(item.componentName.c_str()); rootElementChild->LinkEndChild(rootElementChild1); TiXmlText *content = new TiXmlText(item.addr.c_str()); rootElementChild1->LinkEndChild(content); } } CString appPath = GetAppPath(); CString fullPath = appPath + L"\\layouts.xml"; char fname[4096] = {0}; int len = WideCharToMultiByte(CP_ACP, 0, fullPath, fullPath.GetLength(), NULL, 0, NULL, NULL); WideCharToMultiByte(CP_ACP,0, fullPath, fullPath.GetLength(), fname, len, NULL, NULL); fname[len + 1] = '\0'; pDocument->SaveFile(fname); }
void Lagom::saveSettings() { TiXmlDocument settings; TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "", "" ); settings.LinkEndChild( decl ); TiXmlElement * settingsData = new TiXmlElement( "Settings" ); TiXmlElement * element; TiXmlText * text; AttachTextElementToXML(settingsData,sPropFullscreen,_fullscreen); AttachTextElementToXML(settingsData,sPropEndlessMode,_endless); AttachTextElementToXML(settingsData,sPropSSAO,_SSAO); AttachTextElementToXML(settingsData,sPropFSAA,_FSAA); AttachTextElementToXML(settingsData,sPropXResolution,_xResolution); AttachTextElementToXML(settingsData,sPropYResolution,_yResolution); AttachTextElementToXML(settingsData,sPropSoundVolume,_effectVolume); AttachTextElementToXML(settingsData,sPropMusicVolume,_musicVolume); AttachTextElementToXML(settingsData,sPropDataFile,_dataFile); AttachTextElementToXML(settingsData,sPropPlayerColor,_playerColor); AttachTextElementToXML(settingsData,sPropChallengeStage,_challengeStage); TiXmlElement * highScoresNode = new TiXmlElement(sPropHighScores); for(auto it = _highScores.begin(); it != _highScores.end(); ++it) { TiXmlElement * highScore = new TiXmlElement(sPropHighScoresEntry); highScore->SetAttribute(sPropHighScoresScore,it->_score); highScore->SetAttribute(sPropHighScoresName,it->_name); highScore->SetAttribute(sPropHighScoresStage,it->_stage); highScoresNode->LinkEndChild(highScore); } settingsData->LinkEndChild(highScoresNode); settings.LinkEndChild( settingsData ); settings.SaveFile( sConfigFilename ); }
void COptions::SetServer(wxString path, const CServer& server) { if (!m_pXmlFile) return; if (path == _T("")) return; TiXmlElement *element = m_pXmlFile->GetElement(); while (path != _T("")) { wxString sub; int pos = path.Find('/'); if (pos != -1) { sub = path.Left(pos); path = path.Mid(pos + 1); } else { sub = path; path = _T(""); } char *utf8 = ConvUTF8(sub); if (!utf8) return; TiXmlElement *newElement = element->FirstChildElement(utf8); delete [] utf8; if (newElement) element = newElement; else { char *utf8 = ConvUTF8(sub); if (!utf8) return; TiXmlNode *node = element->LinkEndChild(new TiXmlElement(utf8)); delete [] utf8; if (!node || !node->ToElement()) return; element = node->ToElement(); } } ::SetServer(element, server); if (GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2) return; CInterProcessMutex mutex(MUTEX_OPTIONS); m_pXmlFile->Save(); }
//save tsprite data to an xml file bool TSprite::saveXml( const std::string& savefilename ){ // if theres no source, the s[prite is invalid/incomplete. // we simply wont write it if( src_ == NULL ){ return 0; } filename_ = correctFilepath(savefilename); //xml doc TiXmlDocument doc; //xml header TiXmlDeclaration *decl = new TiXmlDeclaration( "1.0", "", "" ); doc.LinkEndChild( decl ); //tileset header TiXmlElement *root = new TiXmlElement( "TSprite" ); doc.LinkEndChild( root ); //tileset Filename TiXmlElement *fnEl = new TiXmlElement( "Tileset" ); root->LinkEndChild( fnEl ); TiXmlText *fnText = new TiXmlText( src_->getFilename() ); fnEl->LinkEndChild( fnText ); //source dimensions TiXmlElement *countEl = new TiXmlElement( "ImageCount" ); root->LinkEndChild( countEl ); countEl->SetAttribute("frames", numImages_); countEl->SetAttribute("perRow", imagesPerRow_); countEl->SetAttribute("fps", getFps()); //offsets key TiXmlElement *offsetsEl = new TiXmlElement( "Offsets" ); root->LinkEndChild( offsetsEl ); offsetsEl->SetAttribute("x", xOffset_); offsetsEl->SetAttribute("y", yOffset_); return doc.SaveFile( filename_ ); }
void Settings::WriteSettings() { XmlDocument root_doc; TiXmlElement * root = new TiXmlElement("settings"); // audio properties TiXmlElement * audioProps = new TiXmlElement("audio"); audioProps->SetAttribute("music_enabled", mAudioSettings.MusicOn); audioProps->SetAttribute("sfx_enabled", mAudioSettings.SfxOn); root->LinkEndChild(audioProps); root_doc.Save(settingsFilename, root); }
void Properties::saveProperties(char * filename) { TiXmlDocument * doc = new TiXmlDocument(filename); TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "UTF-8", ""); doc->LinkEndChild(decl); std::map<char*, char*>::iterator it = this->properties.begin(); for (; it != this->properties.end(); ++it) { TiXmlElement * element = new TiXmlElement(it->first); TiXmlText * element_text = new TiXmlText(it->second); element->LinkEndChild(element_text); doc->LinkEndChild(element); } doc->SaveFile(); }
void FEPlayer::Serialize(TiXmlDocument* _poXmlDoc, TiXmlElement* _poParent) { TiXmlElement* poPlayerElement = new TiXmlElement("Player"); _poParent->LinkEndChild(poPlayerElement); poPlayerElement->SetAttribute("is_movable", HasFlags(EFEFlag_Movable)); poPlayerElement->SetAttribute("is_deletable", HasFlags(EFEFlag_Deletable)); TiXmlElement* poPosElement = new TiXmlElement("Position"); poPlayerElement->LinkEndChild(poPosElement); poPosElement->SetDoubleAttribute("x", m_vPos.x); poPosElement->SetDoubleAttribute("y", m_vPos.y); }
/** * Creates skeleton object in XML. **/ void IO::saveSkeleton(TiXmlElement *parent, Skeleton *s, Mesh *m) { vector<Joint *> *joints = s->getJoints(); vector<Bone *> *bones = s->getBones(); if (joints->empty() && bones->empty()) return; TiXmlElement *skeletonXML = new TiXmlElement("skeleton"); parent->LinkEndChild(skeletonXML); if (!joints->empty()) { TiXmlElement *jointsXML = new TiXmlElement("joints"); skeletonXML->LinkEndChild(jointsXML); vector<Joint *>::iterator i = joints->begin(); for(; i < joints->end(); i++) { Joint *j = *i; TiXmlElement *jointXML = new TiXmlElement("joint"); const char *name = j->getName(); if (name[0] != 0) // save name only for named joints jointXML->SetAttribute("name", name); jointXML->SetDoubleAttribute("x", j->x); jointXML->SetDoubleAttribute("y", j->y); jointXML->SetAttribute("fixed", j->fixed); jointXML->SetAttribute("selected", j->selected); jointXML->SetAttribute("osc", j->osc); jointsXML->LinkEndChild(jointXML); } } if (!bones->empty()) { saveBones(skeletonXML, bones, joints, m->getVertices()); } }
void ServiceDesc::resolved() { TiXmlElement* tmp; char arr[256] = {0}; Descriptor::resolved(); xml->SetValue("service_descriptor"); sprintf(arr, "0x%x", service_type); tmp = new TiXmlElement("service_type"); tmp->LinkEndChild(new TiXmlText(arr)); xml->LinkEndChild(tmp); sprintf(arr, "0x%x", service_provider_length); tmp = new TiXmlElement("service_provider_length"); tmp->LinkEndChild(new TiXmlText(arr)); xml->LinkEndChild(tmp); if(service_provider_length > 0) { coding_string_to_gb(service_provider, (uint8_t*)arr, service_provider_length); tmp = new TiXmlElement("service_provider"); tmp->LinkEndChild(new TiXmlText(arr)); xml->LinkEndChild(tmp); } sprintf(arr, "0x%x", service_name_length); tmp = new TiXmlElement("service_name_length"); tmp->LinkEndChild(new TiXmlText(arr)); xml->LinkEndChild(tmp); if(service_name_length > 0) { coding_string_to_gb(service_name, (uint8_t*)arr, service_name_length); tmp = new TiXmlElement("service_name"); tmp->LinkEndChild(new TiXmlText(arr)); xml->LinkEndChild(tmp); } }
void writeSchoolXml() { using namespace std; const char * xmlFile = "Students.xml"; TiXmlDocument doc; TiXmlDeclaration * decl = new TiXmlDeclaration("1.0", "", ""); TiXmlElement * schoolElement = new TiXmlElement( "School" ); TiXmlElement * classElement = new TiXmlElement( "Class" ); classElement->SetAttribute("name", "C++"); TiXmlElement * stu1Element = new TiXmlElement("Student"); stu1Element->SetAttribute("name", "tinyxml"); stu1Element->SetAttribute("number", "123"); TiXmlElement * stu1EmailElement = new TiXmlElement("email"); stu1EmailElement->LinkEndChild(new TiXmlText("*****@*****.**") ); TiXmlElement * stu1AddressElement = new TiXmlElement("address"); stu1AddressElement->LinkEndChild(new TiXmlText("中国")); stu1Element->LinkEndChild(stu1EmailElement); stu1Element->LinkEndChild(stu1AddressElement); TiXmlElement * stu2Element = new TiXmlElement("Student"); stu2Element->SetAttribute("name", "jsoncpp"); stu2Element->SetAttribute("number", "456"); TiXmlElement * stu2EmailElement = new TiXmlElement("email"); stu2EmailElement->LinkEndChild(new TiXmlText("*****@*****.**")); TiXmlElement * stu2AddressElement = new TiXmlElement("address"); stu2AddressElement->LinkEndChild(new TiXmlText("美国")); stu2Element->LinkEndChild(stu2EmailElement); stu2Element->LinkEndChild(stu2AddressElement); classElement->LinkEndChild(stu1Element); classElement->LinkEndChild(stu2Element); schoolElement->LinkEndChild(classElement); doc.LinkEndChild(decl); doc.LinkEndChild(schoolElement); bool issuccess = doc.SaveFile(xmlFile); cout<<issuccess; }
// save world information into file void MapInfoXmlWriter::SaveTexts(const std::string Filename, const std::map<long, std::string> &txts) { TiXmlDocument doc; TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "UTF8", "" ); doc.LinkEndChild( decl ); TiXmlElement * root = new TiXmlElement("texts"); doc.LinkEndChild( root ); std::map<long, std::string>::const_iterator it = txts.begin(); std::map<long, std::string>::const_iterator end = txts.end(); for(; it != end; ++it) { TiXmlElement * txt = new TiXmlElement( "text" ); txt->SetAttribute("id", it->first); root->LinkEndChild(txt); txt->LinkEndChild(new TiXmlText(it->second)); } doc.SaveFile(Filename); }
TiXmlElement* TLFSemanticDictinaryItem::SaveXML() { TiXmlElement* dscr = new TiXmlElement(this->GetName()); dscr->SetAttribute("noun", this->m_strWord.c_str()); for (int i = 0; i < this->m_Detectors.GetCount(); i++) { ILFDetectEngine* di = (ILFDetectEngine*)this->m_Detectors.Get(i); TiXmlElement* e = di->SaveXML(); if (e != NULL) dscr->LinkEndChild(e); } return dscr; }
void DataStreamAlignmentDesc::resolved() { TiXmlElement* tmp; char arr[16] = {0}; Descriptor::resolved(); xml->SetValue("data_stream_alignment_descriptor"); sprintf(arr, "0x%x", alignment_type); tmp = new TiXmlElement("alignment_type"); tmp->LinkEndChild(new TiXmlText(arr)); xml->LinkEndChild(tmp); }
//////////////////////////////////////////////////////////////////////// /// /// @fn void ConfigScene::creerDOM ( TiXmlNode& node ) const /// /// Cette fonction écrit les valeurs de la configuration dans un élément XML. /// /// @return Aucune. /// //////////////////////////////////////////////////////////////////////// void ConfigScene::creerDOM ( TiXmlNode* node ) { // Créer le noeud 'configuration' TiXmlElement* elementConfiguration = new TiXmlElement("configuration"); // Créer le noeud scene et définir ses attributs TiXmlElement* elementScene = new TiXmlElement("CScene"); elementScene->SetAttribute("Calculs_par_image", 20); CALCULS_PAR_IMAGE=20; elementScene->SetDoubleAttribute("CoefFriSol",2); coefFriSol_=2; elementScene->SetDoubleAttribute("CoefFriSable",6); coefFriSable_=6; elementScene->SetDoubleAttribute("CoefRebondMur",0.95); coefRebondMur_=0.95; elementScene->SetDoubleAttribute("AccelBonus",0); accelBonus_=0; elementScene->SetAttribute("TailleEditionLargeur", 500);//Placeholder a modifier elementScene->SetAttribute("TailleEditionHauteur", 500); toucheClavier_[0]=37; toucheClavier_[1]=39; toucheClavier_[2]=38; toucheClavier_[3]=40; toucheClavier_[4]=32; tailleEdition_[0]=500; tailleEdition_[1]=500; toucheOptionClavier_.push_back("gauche"); toucheOptionClavier_.push_back("droit"); toucheOptionClavier_.push_back("haut"); toucheOptionClavier_.push_back("bas"); toucheOptionClavier_.push_back("espace"); elementScene->SetAttribute("toucheClavierGauche", 37); elementScene->SetAttribute("toucheClavierDroit", 39); elementScene->SetAttribute("toucheClavierHaut", 38); elementScene->SetAttribute("toucheClavierBas", 40); elementScene->SetAttribute("toucheClavierEspace", 32); elementScene->SetAttribute("toucheOptionGauche", toucheOptionClavier_[0].c_str()); elementScene->SetAttribute("toucheOptionDroit", toucheOptionClavier_[1].c_str()); elementScene->SetAttribute("toucheOptionHaut", toucheOptionClavier_[2].c_str()); elementScene->SetAttribute("toucheOptionBas", toucheOptionClavier_[3].c_str()); elementScene->SetAttribute("toucheOptionEspace", toucheOptionClavier_[4].c_str()); // Adjoindre le noeud 'elementScene' elementConfiguration->LinkEndChild(elementScene); // Adjoindre le noeud 'configuration' au noeud principal // (Rappel : pas besoin de libérer la mémoire de elementConfiguration // puisque toutes les fonctions Link... le font pour nous) node->LinkEndChild(elementConfiguration); }
void CreateHISReaderXML(const std::map<int, HISReader> &mapReader, char *strHISReader) { TiXmlDocument *XmlDoc = NULL; TiXmlElement *RootElement = NULL; TiXmlElement *Segment = NULL; TiXmlElement *Column = NULL; TiXmlDeclaration HeadDec; TiXmlPrinter Printer; // 创建XML文档 XmlDoc = new TiXmlDocument(); // 增加XML的头部说明 HeadDec.Parse("<?xml version=\"1.0\" encoding=\"gb2312\" ?>", 0, TIXML_ENCODING_UNKNOWN); XmlDoc->LinkEndChild(&HeadDec); RootElement = new TiXmlElement("SEGMENTS"); RootElement->SetAttribute("PROGRAMID", "001"); Segment = new TiXmlElement("SEGMENT"); Segment->SetAttribute("ID", 2); std::map<int, HISReader>::const_iterator iter = mapReader.begin(); for (; iter != mapReader.end(); ++iter) { const HISReader &stHIS = iter->second; Column = new TiXmlElement("COLUMN"); Column->SetAttribute("ID", iter->first); Column->SetAttribute("DESC", stHIS.strDesc.c_str()); Column->SetAttribute("VALUE", stHIS.strValue.c_str()); Segment->LinkEndChild(Column); } RootElement->LinkEndChild(Segment); XmlDoc->LinkEndChild(RootElement); XmlDoc->Accept(&Printer); strcpy(strHISReader, Printer.CStr()); }
// save world information into file void MapInfoXmlWriter::SaveWorld(const std::string &Filename, WorldInfo & wi) { TiXmlDocument doc; std::string s; TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" ); doc.LinkEndChild( decl ); TiXmlElement * root = new TiXmlElement("World"); doc.LinkEndChild( root ); root->SetAttribute("name", wi.Name); root->SetAttribute("firstmap", wi.FirstMap); root->SetAttribute("firstsparea", wi.FirstSpawning); TiXmlElement * desc = new TiXmlElement( "description" ); root->LinkEndChild(desc); desc->LinkEndChild(new TiXmlText(wi.Description)); TiXmlElement * maps = new TiXmlElement( "maps" ); root->LinkEndChild(maps); std::map<std::string, MapInfo>::iterator it = wi.Maps.begin(); std::map<std::string, MapInfo>::iterator end = wi.Maps.end(); for(; it != end; ++it) { TiXmlElement * map = new TiXmlElement( "Map" ); maps->LinkEndChild(map); std::string worldmapname = "Lba1Original"; std::string mapname2 = it->second.Files["Maps"]; mapname2 = mapname2.substr(0, mapname2.find_last_of("/")); mapname2 = mapname2.substr(mapname2.find_last_of("/")+1); if(mapname2 == "Lba2") worldmapname = "Lba2Original"; map->SetAttribute("name", it->first); map->SetAttribute("type", it->second.Type); map->SetAttribute("music", "Worlds/"+worldmapname+"/"+it->second.Music); map->SetAttribute("repeatmusic", it->second.MusicLoop); map->SetAttribute("AutoCameraType", 1); map->SetAttribute("IsInstance", "false"); map->SetAttribute("HurtFallFactor", 2); TiXmlElement * descm = new TiXmlElement( "description" ); map->LinkEndChild(descm); descm->LinkEndChild(new TiXmlText(it->second.Description)); } doc.SaveFile(Filename); }
void CleanerConfig::writeBuffer() const { TiXmlDocument doc; TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "UTF-8", ""); doc.LinkEndChild( decl ); TiXmlElement * root = new TiXmlElement( "PokerTHCleaner" ); doc.LinkEndChild( root ); TiXmlElement * config; config = new TiXmlElement( "Configuration" ); root->LinkEndChild( config ); size_t i; for (i=0; i<configBufferList.size(); i++) { TiXmlElement *tmpElement = new TiXmlElement(configBufferList[i].name); config->LinkEndChild( tmpElement ); tmpElement->SetAttribute("value", configBufferList[i].defaultValue); if(configBufferList[i].type == CONFIG_TYPE_INT_LIST || configBufferList[i].type == CONFIG_TYPE_STRING_LIST) { tmpElement->SetAttribute("type", "list"); list<string> tempList = configBufferList[i].defaultListValue; list<string>::iterator it; for(it = tempList.begin(); it != tempList.end(); ++it) { TiXmlElement *tmpSubElement = new TiXmlElement(configBufferList[i].defaultValue); tmpElement->LinkEndChild( tmpSubElement ); tmpSubElement->SetAttribute("value", *it); } } } doc.SaveFile( configFileName ); }
bool Resource::SaveToFileXML(const std::string& filename) { sourceFile = filename; onSave(); if (!header) { header = new DataTree; header->rootNode().newChild("type").element().set(typeName); header->rootNode().newChild("id").element().set(idName); header->rootNode().newChild("bundle").element().set(bundleName); // header->rootNode().newChild("version").element().set(1.0); } TiXmlDocument doc; TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "", "" ); doc.LinkEndChild( decl ); TiXmlElement *element = new TiXmlElement("root"); doc.LinkEndChild( element ); // if (!root->numChildren()) doc.Print(); TiXmlElement *header_node = new TiXmlElement("header"); element->LinkEndChild(header_node); header->nodeToXML(&header->rootNode(),header_node); TiXmlElement *properties_node = new TiXmlElement("properties"); element->LinkEndChild(properties_node); properties->nodeToXML(&properties->rootNode(),properties_node); doc.SaveFile(filename.c_str()); return true; }
void HelloWorld::createTinyXmlFile() { try { //创建一个XML的文档对象。 TiXmlDocument *myDocument = new TiXmlDocument(); //创建一个根元素并连接。 TiXmlElement *RootElement = new TiXmlElement("Persons"); myDocument->LinkEndChild(RootElement); //创建一个Person元素并连接。 TiXmlElement *PersonElement = new TiXmlElement("Person"); RootElement->LinkEndChild(PersonElement); //设置Person元素的属性。 PersonElement->SetAttribute("ID", "1"); //创建name元素、age元素并连接。 TiXmlElement *NameElement = new TiXmlElement("name"); TiXmlElement *AgeElement = new TiXmlElement("age"); PersonElement->LinkEndChild(NameElement); PersonElement->LinkEndChild(AgeElement); //设置name元素和age元素的内容并连接。 TiXmlText *NameContent = new TiXmlText("Yarin"); TiXmlText *AgeContent = new TiXmlText("24"); NameElement->LinkEndChild(NameContent); AgeElement->LinkEndChild(AgeContent); char filePath[1024]= {'\0'}; memset(filePath,0,sizeof(filePath)); strcat(filePath,CCFileUtils::sharedFileUtils()->getWriteablePath().c_str()); strcat(filePath,"CreatedTinyXml.xml"); myDocument->SaveFile(filePath);//保存到文件 } catch (string& e) { return ; } return ; }
void CRemoteDataObject::Finalize() { // Convert data into XML TiXmlElement* pElement = m_xmlFile.CreateEmpty(); pElement = pElement->LinkEndChild(new TiXmlElement("RemoteDataObject"))->ToElement(); AddTextElement(pElement, "ProcessId", m_processId); TiXmlElement* pServer = pElement->LinkEndChild(new TiXmlElement("Server"))->ToElement(); SetServer(pServer, m_server); AddTextElement(pElement, "Path", m_path.GetSafePath()); TiXmlElement* pFiles = pElement->LinkEndChild(new TiXmlElement("Files"))->ToElement(); for (std::list<t_fileInfo>::const_iterator iter = m_fileList.begin(); iter != m_fileList.end(); ++iter) { TiXmlElement* pFile = pFiles->LinkEndChild(new TiXmlElement("File"))->ToElement(); AddTextElement(pFile, "Name", iter->name); AddTextElement(pFile, "Dir", iter->dir ? 1 : 0); AddTextElement(pFile, "Size", iter->size.ToString()); AddTextElement(pFile, "Link", iter->link ? 1 : 0); } }
void Phy2dWorld::saveToXML(TiXmlElement *xmlNodePhy2DWorld) { TiXmlElement *actorsNode = new TiXmlElement("Actors"); xmlNodePhy2DWorld->LinkEndChild(actorsNode); int actorNum = (int)m_actors.size(); for(int i=0; i<actorNum; i++) { TiXmlElement * node = new TiXmlElement("Actor"); m_actors[i]->saveToXML(node); actorsNode->LinkEndChild(node); } }
TiXmlElement* Kml::StandardHead( TiXmlDocument& xmlDoc, wxString name ) { TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "UTF-8", "" ); xmlDoc.LinkEndChild( decl ); TiXmlElement* kml = new TiXmlElement( "kml" ); kml->SetAttribute( "xmlns:atom", "http://www.w3.org/2005/Atom" ); kml->SetAttribute( "xmlns", "http://www.opengis.net/kml/2.2" ); kml->SetAttribute( "xmlns:gx", "http://www.google.com/kml/ext/2.2" ); kml->SetAttribute( "xmlns:kml", "http://www.opengis.net/kml/2.2" ); if( insertQtVlmExtendedData ) kml->SetAttribute( "xmlns:vlm", "http://virtual-loup-de-mer.org" ); xmlDoc.LinkEndChild( kml ); TiXmlElement* document = new TiXmlElement( "Document" ); kml->LinkEndChild( document ); TiXmlElement* docName = new TiXmlElement( "name" ); document->LinkEndChild( docName ); TiXmlText* docNameVal = new TiXmlText( name.mb_str( wxConvUTF8 ) ); docName->LinkEndChild( docNameVal ); return document; }