// A font is specified by two files: a TGA file with the rendered // chars for the font, and a XML file which contains global info // about the font and the texture coordinates and width of each char // The parameter fontName is the filename without extension. // It is assumed that the files are "fontName.xml" and "fontName.tga" bool VSFontLib::load(std::string fontName) { // Test if image file exists FILE *fp; std::string s; s = fontName + ".tga"; fp = fopen(s.c_str(),"r"); if (fp == NULL) { VSResourceLib::sLogError.addMessage("Unable to find font texture: %s", s.c_str()); return false; } mFontTex = loadRGBATexture(s); s = fontName + ".xml"; TiXmlDocument doc(s.c_str()); bool loadOK = doc.LoadFile(); if (!loadOK) { VSResourceLib::sLogError.addMessage("Problem reading the XML font definition file: %s", s.c_str()); return false; } TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); TiXmlElement *pElem; pElem = hDoc.FirstChildElement().Element(); if (0 == pElem) return false; hRoot = TiXmlHandle(pElem); pElem->QueryIntAttribute("numchars",&mNumChars); if (mNumChars == 0) return false; hRoot = hRoot.FirstChild("characters"); pElem = hRoot.FirstChild("chardata").Element(); if (pElem) pElem->QueryIntAttribute("hgt",&mHeight); VSFLChar aChar; int charCode, numChars = 0; for(; 0 != pElem; pElem = pElem->NextSiblingElement(), ++numChars) { pElem->QueryIntAttribute("char",&charCode); pElem->QueryIntAttribute("wid",&(aChar.width)); pElem->QueryFloatAttribute("X1", &(aChar.x1)); pElem->QueryFloatAttribute("X2", &(aChar.x2)); pElem->QueryFloatAttribute("Y1", &(aChar.y1)); pElem->QueryFloatAttribute("Y2", &(aChar.y2)); pElem->QueryIntAttribute("A", &(aChar.A)); pElem->QueryIntAttribute("C", &(aChar.C)); mChars[(unsigned char)charCode] = aChar; } VSResourceLib::sLogInfo.addMessage("Font has %d chars", numChars); return true; }
/** * 从字符串中初始化 */ bool tixmlCode::initFromString(const char *content) { TiXmlDocument doc; doc.Parse(content); static std::string CODE="code"; static std::string READ="read"; TiXmlHandle hDoc(&doc); TiXmlElement* pElem = NULL; pElem=hDoc.FirstChildElement().Element(); for(; pElem; pElem=pElem->NextSiblingElement()) { const char *pKey=pElem->Value(); tixmlCodeNode *node = new tixmlCodeNode(); node->init(pElem); if (node->nodeName == CODE) { parseCode(node); } else if (node->nodeName == READ) { std::string fileName = node->getAttr("file"); init(fileName.c_str()); // 加载其他文本进入当前执行环境 } else { takeNode(node); // 调用使用者的方法 } } return true; }
ETHEntityProperties::ETHEntityProperties(const str_type::string& filePath, const Platform::FileManagerPtr& fileManager) { ETHEntityMaterial::Reset(); Reset(); TiXmlDocument doc(filePath); str_type::string content; fileManager->GetUTF16FileString(filePath, content); if (!doc.LoadFile(content, TIXML_ENCODING_LEGACY)) { ETH_STREAM_DECL(ss) << GS_L("Couldn't load file: ") << filePath; ETHResourceProvider::Log(ss.str(), Platform::Logger::ERROR); return; } TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); TiXmlElement *pElem = hDoc.FirstChildElement().Element(); if (!pElem) { ETH_STREAM_DECL(ss) << GS_L("The current file seems to be invalid: ") << filePath; ETHResourceProvider::Log(ss.str(), Platform::Logger::ERROR); return; } hRoot = TiXmlHandle(pElem); entityName = Platform::GetFileName(filePath); if (ReadFromXMLFile(hRoot.FirstChildElement().Element())) { successfullyLoaded = true; } }
bool MProject::loadXML(const char * filename) { char rep[256]; if(! filename) return false; // get rep getRepertory(rep, filename); // read document TiXmlDocument doc(filename); if(! doc.LoadFile()) return false; TiXmlHandle hDoc(&doc); TiXmlElement * rootNode; TiXmlHandle hRoot(0); // maratis rootNode = hDoc.FirstChildElement().Element(); if(! rootNode) return false; if(strcmp(rootNode->Value(), "Maratis") != 0) return false; hRoot = TiXmlHandle(rootNode); // Project TiXmlElement * projectNode = rootNode->FirstChildElement("Project"); if(! projectNode) return false; // renderer TiXmlElement * rendererNode = projectNode->FirstChildElement("renderer"); if(rendererNode) { const char * name = rendererNode->Attribute("name"); if(name) { renderer = name; } } // start TiXmlElement * startNode = projectNode->FirstChildElement("start"); if(startNode) { const char * file = startNode->Attribute("file"); if(file) { char levelFilename[256]; getGlobalFilename(levelFilename, rep, file); startLevel = levelFilename; } } return true; }
/* -------------------------------------------------------------------------------------------------- - get a text from file -------------------------------------------------------------------------------------------------- */ std::map<long, std::string> MapInfoXmlReader::LoadTextFile(const std::string &Filename) { std::map<long, std::string> res; TiXmlDocument doc(Filename); if (!doc.LoadFile()) return res; TiXmlHandle hDoc(&doc); TiXmlElement* pElem; // block: text attributes { pElem=hDoc.FirstChildElement().Element(); // should always have a valid root but handle gracefully if it does if (!pElem) return res; // for each text pElem=pElem->FirstChildElement("quotes"); pElem=pElem->FirstChildElement(); for(;pElem; pElem=pElem->NextSiblingElement()) { long ctid = -1; pElem->QueryValueAttribute("id", &ctid); if(pElem->FirstChild()) res[ctid] = pElem->FirstChild()->Value(); } } return res; }
//----------------------------------------------------------------------- int XmlConvert(InStm *pin, const strvector &css, const strvector &fonts, const strvector &mfonts, XlitConv *xlitConv, OutPackStm *pout) { // perform pass 1 to determine fb2 document structure and to collect all cross-references inside the fb2 file UnitArray units; // The input file name is pin->UIFileName(); XMLDocument doc; doc.LoadFile(pin->UIFileName().c_str()); XMLHandle hDoc(&doc); XMLHandle fb = hDoc.FirstChildElement("FictionBook"); XMLHandle desc = fb.FirstChildElement("description"); XMLHandle titleInfo = desc.FirstChildElement("title-info"); XMLHandle genre = titleInfo.FirstChildElement("genre"); XMLHandle genreInfo = genre.FirstChild(); const char* txt = genreInfo.ToNode()->Value(); // "Ciencia-Ficción" // Now build from the above the damn epub! // Go directly to DoConvertionPass2 and substitute XML calls to make epub. // CONVERTION PASS 1 (DETERMINE DOCUMENT STRUCTURE AND COLLECT ALL CROSS-REFERENCES INSIDE THE FB2 FILE) Ptr<ConverterPass1> conv = new ConverterPass1(&units); conv->XmlScan(hDoc); //DoConvertionPass1(CreateScanner(pin), &units); //pin->Rewind(); // sanity check if (units.size() == 0) InternalError(__FILE__, __LINE__, "I don't know why but it happened that there is no content in input file!"); // perform pass 2 to create epub document //XmlConversionPass2(hDoc, css, fonts, mfonts, xlitConv, &units, pout); //DoConvertionPass2(CreateScanner(pin), css, fonts, mfonts, xlitConv, &units, pout); return 0; }
bool TStatDatabase::LoadDatabase(const char* lpFileName) { CloseDatabase(); TiXmlDocument doc(lpFileName); if (!doc.LoadFile()) return false; TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); TiXmlElement* elem = hDoc.FirstChildElement().Element(); if (strcmp(elem->Value(), "awpStatDB") != 0) return false; for(TiXmlNode* child = elem->FirstChild(); child; child = child->NextSibling() ) { const char* name = child->Value(); if (strcmp(name, "EntryID") != 0) return false; TDbEntry* e = new TDbEntry(0, ""); if (e->LoadXML(child->ToElement())) this->m_entries.Add(e); else { delete e; return false; } } this->m_isChanged = false; this->m_dbName = lpFileName; return true; }
DefaultShaderParameters::DefaultShaderParameters(string filename) { TiXmlDocument doc(filename); if (!doc.LoadFile()) { return; } TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem=hDoc.FirstChildElement().Element(); if (!pElem) { return; } pElem=pElem->FirstChildElement(); for(pElem; pElem; pElem=pElem->NextSiblingElement()) { string entry_name = pElem->ValueStr(); if (entry_name=="Parameter") { DefaultShaderParameter *parameter = new DefaultShaderParameter(); parameter->read(pElem); parameters.push_back(parameter); } } }
/** Chargement de la configuration **/ void GameConfig::LoadConfig(){ TiXmlDocument doc("config/config.xml"); doc.LoadFile(); TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); TiXmlElement* pElem; pElem=hDoc.FirstChild("img").FirstChild().Element(); for(; pElem; pElem=pElem->NextSiblingElement()){ imgAnim newAnim; sf::Texture newImg; if(!newImg.LoadFromFile(pElem->Attribute("path"))){ cerr<<"Image not found: "<<pElem->Attribute("path")<<endl; exit(0); } newAnim.img=newImg; newAnim.nbrCollum=atoi(pElem->Attribute("nbrCollums")); newAnim.nbrLine=atoi(pElem->Attribute("nbrLines")); g_imgManag[pElem->Attribute("name")]=newAnim; } pElem=hDoc.FirstChild("sound").FirstChild().Element(); for(; pElem; pElem=pElem->NextSiblingElement()){ sf::SoundBuffer newSound; newSound.LoadFromFile(pElem->Attribute("path")); g_soundManag[pElem->Attribute("name")]=newSound; } pElem=hDoc.FirstChild("config").FirstChild().Element(); for(; pElem; pElem=pElem->NextSiblingElement()){ GameConfig::g_config[pElem->Attribute("name")]=atoi(pElem->Attribute("value")); } }
void MapSelectionMenu::setupOptions() { title = L"Load Map"; // Load xml in. Store Paths in pathnames // foreach map // pathnames[i++] = path // addoption(name, i) // leave UIMenu::setupOptions(); TiXmlDocument doc( "maplist.xml"); if(doc.LoadFile()) { TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement().Element(); hRoot=TiXmlHandle(pElem); TiXmlElement* pMap = hRoot.FirstChild("Map").ToElement(); int i=0; for(pMap; pMap; pMap = pMap->NextSiblingElement("Map")) { pathNames.insert(pair<int, string>(i, pMap->Attribute("path"))); addOption(Utility::widen(pMap->Attribute("name")), i); i++; } } //addOption(L"Pea Island, 2p", 0); //addOption(L"Dev Map, 2p", 1); UIMenu::setupOptions(); }
ShaderEffect *ShaderEffect::LoadXML(const char* xmlFileNamePtr, const char* indentifier) { std::string fullPath = ContentManager::theContentPath + xmlFileNamePtr; TiXmlDocument doc(fullPath.c_str()); if(!doc.LoadFile()) { InternalOutput::GetReference().Error( "Failed to load %s, does the file exist?\n", xmlFileNamePtr); return 0; } TiXmlHandle hDoc(&doc); TiXmlElement* elementPtr; elementPtr = hDoc.FirstChildElement().Element(); if( !elementPtr ) { InternalOutput::GetReference().Error( "Failed to load %s, is the file empty?\n", xmlFileNamePtr); return nullptr; } unsigned int techniqueCount = 0; TiXmlElement *techElementPtr = elementPtr->FirstChildElement("Technique"); while(nullptr != techElementPtr) { ++techniqueCount; techElementPtr = techElementPtr->NextSiblingElement("Technique"); } if(0 == techniqueCount) { InternalOutput::GetReference().Error( "Failed to load %s, does the file contain any techniques?\n", xmlFileNamePtr); return nullptr; } ShaderEffect *effectPtr = new ShaderEffect; effectPtr->shaderTechiquesCount = techniqueCount; effectPtr->shaderTechiques = new ShaderTechnique[effectPtr->shaderTechiquesCount]; techElementPtr = elementPtr->FirstChildElement("Technique"); unsigned int techIndex = 0; while(nullptr != techElementPtr) { // Load the current technique if(!effectPtr->shaderTechiques[techIndex++].LoadTechniqueFromElement(techElementPtr)) { InternalOutput::GetReference().Error( "Failed to load %s, could not load techniques\n", xmlFileNamePtr); delete effectPtr; return 0; } techElementPtr = techElementPtr->NextSiblingElement("Technique"); } effectPtr->name = xmlFileNamePtr; return effectPtr; }
void ObjectProduction::load(string filename) { TiXmlDocument doc(filename); if (!doc.LoadFile()) { Error::addMessage(Error::FILE_NOT_FOUND, LIBGENS_OBJECT_PRODUCTION_ERROR_FILE + filename); return; } TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem=hDoc.FirstChildElement().Element(); if (!pElem) { Error::addMessage(Error::EXCEPTION, LIBGENS_OBJECT_PRODUCTION_ERROR_FILE_ROOT); return; } sorted_entry_names.clear(); pElem=pElem->FirstChildElement(); for(pElem; pElem; pElem=pElem->NextSiblingElement()) { ObjectPhysics *object=new ObjectPhysics(); object->readXML(pElem); object_entries.push_back(object); sorted_entry_names.insert(object->getName()); } }
void ObjectLibrary::loadDatabase(string filename) { TiXmlDocument doc(filename); if (!doc.LoadFile()) { Error::addMessage(Error::FILE_NOT_FOUND, LIBGENS_LIBRARY_ERROR_FILE + filename); return; } TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem=hDoc.FirstChildElement().Element(); if (!pElem) { Error::addMessage(Error::EXCEPTION, LIBGENS_LIBRARY_ERROR_FILE_ROOT); return; } pElem=pElem->FirstChildElement(); for(pElem; pElem; pElem=pElem->NextSiblingElement()) { string entry_name=""; string category_name=""; string folder_name=""; entry_name = pElem->ValueStr(); pElem->QueryValueAttribute(LIBGENS_LIBRARY_NAME_ATTRIBUTE, &category_name); pElem->QueryValueAttribute(LIBGENS_LIBRARY_FOLDER_ATTRIBUTE, &folder_name); if ((entry_name==LIBGENS_LIBRARY_ENTRY) && category_name.size() && folder_name.size()) { loadCategory(category_name, folder_name); } } }
bool Phy2dWorld::loadFromXMLFile(const char* xmlFile) { TiXmlDocument doc(xmlFile); if (!doc.LoadFile()) return false; TiXmlHandle hDoc(&doc); TiXmlElement* pDocRoot = hDoc.FirstChildElement().Element(); // should always have a valid root but handle gracefully if it does if (!pDocRoot) return false; stringc docRootName=pDocRoot->Value(); if(docRootName != "FLTResXML") return false; TiXmlHandle hDocRoot(pDocRoot); TiXmlElement* pXMLNodePhy2DWorld = hDocRoot.FirstChild("Phy2DWorld").Element(); if(pXMLNodePhy2DWorld==0) return false; bool bLoaded = loadFromXML(pXMLNodePhy2DWorld); if(bLoaded) { m_xmlFileName = xmlFile; } return bLoaded; }
bool GibbsTrackingFilter< ItkQBallImageType >::LoadParameters() { m_AbortTracking = true; try { if( m_LoadParameterFile.length()==0 ) { m_AbortTracking = false; return true; } MITK_INFO << "GibbsTrackingFilter: loading parameter file " << m_LoadParameterFile; TiXmlDocument doc( m_LoadParameterFile ); doc.LoadFile(); TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement().Element(); hRoot = TiXmlHandle(pElem); pElem = hRoot.FirstChildElement("parameter_set").Element(); string iterations(pElem->Attribute("iterations")); m_Iterations = boost::lexical_cast<unsigned long>(iterations); string particleLength(pElem->Attribute("particle_length")); m_ParticleLength = boost::lexical_cast<float>(particleLength); string particleWidth(pElem->Attribute("particle_width")); m_ParticleWidth = boost::lexical_cast<float>(particleWidth); string partWeight(pElem->Attribute("particle_weight")); m_ParticleWeight = boost::lexical_cast<float>(partWeight); string startTemp(pElem->Attribute("temp_start")); m_StartTemperature = boost::lexical_cast<float>(startTemp); string endTemp(pElem->Attribute("temp_end")); m_EndTemperature = boost::lexical_cast<float>(endTemp); string inExBalance(pElem->Attribute("inexbalance")); m_InexBalance = boost::lexical_cast<float>(inExBalance); string fiberLength(pElem->Attribute("fiber_length")); m_MinFiberLength = boost::lexical_cast<float>(fiberLength); string curvThres(pElem->Attribute("curvature_threshold")); m_CurvatureThreshold = cos(boost::lexical_cast<float>(curvThres)*M_PI/180); m_AbortTracking = false; MITK_INFO << "GibbsTrackingFilter: parameter file loaded successfully"; return true; } catch(...) { MITK_INFO << "GibbsTrackingFilter: could not load parameter file"; return false; } }
//-------------------------------------------------------------- void ofxMagneticApp::__setupCalibration() { // Get calibration points from XML TiXmlHandle hDoc(&__calibrationXML); TiXmlHandle hCalibration = hDoc.FirstChild("calibration"); // Initialize arrays __calibrationCameraPoints = new ofPoint[__calibrationPointCount]; __calibrationScreenPoints = new ofPoint[__calibrationPointCount]; __calibrationTriangles = new int[__calibrationTriangleCount]; // Find distance between lines in grid float deltaX = (float)__captureWidth / (float)(__calibrationColumns - 1); float deltaY = (float)__captureHeight / (float)(__calibrationRows - 1); // Iterate through rows int t = 0; for (int i = 0; i < __calibrationRows; i++) { // Iterate through columns for (int j = 0; j < __calibrationColumns; j++) { // Omit last point in triangle mesh if (i < __calibrationRows - 1 && j < __calibrationColumns - 1) { // Create a downward pointing right triangle on left side of rectangle __calibrationTriangles[t + 0] = (j + 0) + (i + 0) * __calibrationColumns; __calibrationTriangles[t + 1] = (j + 1) + (i + 0) * __calibrationColumns; __calibrationTriangles[t + 2] = (j + 0) + (i + 1) * __calibrationColumns; t += 3; // And an upward pointing right triangle on right side of the rectangle __calibrationTriangles[t + 0] = (j + 1) + (i + 0) * __calibrationColumns; __calibrationTriangles[t + 1] = (j + 1) + (i + 1) * __calibrationColumns; __calibrationTriangles[t + 2] = (j + 0) + (i + 1) * __calibrationColumns; t += 3; } // Calculate point index int index = i * __calibrationColumns + j; // Get calibration point from XML TiXmlElement* pPoint = hCalibration.Child("point", index).ToElement(); // Set grid point on screen and camera __calibrationScreenPoints[index].set(deltaX * (float)j, deltaY * (float)i); __calibrationCameraPoints[index].set(atof(pPoint->Attribute("x")) * (float)__captureWidth, atof(pPoint->Attribute("y")) * (float)__captureHeight); } } }
bool Script::loadScriptFile(const std::string &file) { std::string finalPath; // handle relative paths #ifdef _MSC_VER if (file.find(":") == -1) #else if (file[0] != '/') #endif { char *szCurrentDir = getcwd(NULL, 0); if (szCurrentDir == 0) { printf("can't get current dir - try using a full path\n"); return false; } std::string strFullPath = szCurrentDir; #ifdef _MSC_VER strFullPath += "\\"; #else strFullPath += "/"; #endif strFullPath += file; finalPath = strFullPath; } else { finalPath = file; } TiXmlDocument doc(finalPath); if (!doc.LoadFile()) { printf("Can't load xml file.\n"); return false; } TiXmlHandle hDoc(&doc); TiXmlElement* pElem = NULL; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement("script").Element(); if (!pElem) // no script item... return false; for (pElem = pElem->FirstChildElement("request"); pElem; pElem = pElem->NextSiblingElement()) { loadRequestElement(pElem); } return true; }
int _tmain(int argc, _TCHAR* argv[]) { TiXmlDocument doc; if (!doc.LoadFile("Face2ieye.xml")) { printf("Cannot load file: Face2ieye.xml \n"); return 1; } TiXmlHandle hDoc(&doc); TiXmlElement* pElem = NULL; pElem = hDoc.FirstChildElement().Element(); if (!pElem) { printf("error: invalid configuration file.\n"); return 1; } const char* name = pElem->Value(); if (strcmp(name, "Face2ieye") != 0) { printf("error: invalid configuration file.\n"); return 1; } string strPath = pElem->Attribute("db"); _finddata_t filesInfo; int num_images = 0; long handle = 0; if ((handle = _findfirst((char*)((strPath + "*.face").c_str()), &filesInfo)) != -1) { do { string name = strPath + filesInfo.name; TLFFaceImageDescriptor fd; if (fd.LoadFromFile(name.c_str())) { string out_name = LFChangeFileExt(name, ".ieye"); TLFRoiImageDescriptor rd; rd.AddRoi(fd.GetRoi()->GetRoi().p, fd.GetRoi()->GetRoi().p1); rd.SaveToFile(out_name.c_str()); num_images++; if (num_images % 100 == 0) printf(">"); } } while (!_findnext(handle, &filesInfo)); } _findclose(handle); printf("\nprocessed %i images\n", num_images); printf("done.\n"); return 0; }
void BIXFConverter::convertToBIXF(string source, string dest, int mode_flag) { File file(dest, LIBGENS_FILE_WRITE_BINARY); vector<string> string_table; vector<unsigned char> data; if (file.valid()) { TiXmlDocument doc(source); doc.LoadFile(); TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem=hDoc.FirstChildElement().Element(); for(pElem; pElem; pElem=pElem->NextSiblingElement()) { convertToBIXF(pElem, string_table, data, mode_flag); } // Write Binary Data unsigned char header=0x01; file.writeString("BIXF"); file.writeUChar(&header); file.fixPadding(20); unsigned int total_data_size=data.size(); unsigned int total_string_size=0; unsigned int total_string_count=string_table.size(); for (size_t c=0; c<data.size(); c++) { file.writeUChar(&(data[c])); } // Apparently it needs three zeros at the end of the data unsigned char zero=0; file.writeUChar(&zero); file.writeUChar(&zero); file.writeUChar(&zero); total_string_size += 3; for (size_t c=0; c<string_table.size(); c++) { file.writeString(&(string_table[c])); total_string_size += string_table[c].size() + 1; } file.goToAddress(8); file.writeInt32(&total_data_size); file.writeInt32(&total_string_size); file.writeInt32(&total_string_count); file.close(); } }
void ArchiveTree::load(string filename) { TiXmlDocument doc(filename); doc.LoadFile(); TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); TiXmlElement *pElem=hDoc.FirstChildElement().Element(); for(pElem; pElem; pElem=pElem->NextSiblingElement()) { string entry_name = pElem->ValueStr(); printf("%s\n", entry_name.c_str()); } }
void Config::loadFile(const std::string& fileName) throw(FileOpenException,DataParsingException) { // code mostly basis on TinyXML example TiXmlDocument doc(fileName.c_str()); if (!doc.LoadFile()) throw FileOpenException(fileName); TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); std::string m_name; // check what for it is // block: name { pElem=hDoc.FirstChildElement().Element(); // should always have a valid root. If does not - throw exception. if (!pElem) throw XML::XMLParsingException(fileName); m_name=pElem->Value(); // save this for later hRoot=TiXmlHandle(pElem); } // <configuration> { config.clear(); // trash existing table pElem=hRoot.FirstChild().Element(); for(; pElem; pElem=pElem->NextSiblingElement()) { std::string pKey = pElem->Value(); std::string pText = pElem->GetText(); std::string pAttr = pElem->Attribute("name"); SupportedTypesVariant value; try { value = fromStringToTypeVariableMap[pKey](pText); } catch(boost::bad_lexical_cast&) { throw XML::WrongTypeOfValueException(pKey,pText); } if (pKey.length() > 0 && pText.length() > 0) { config[pAttr] = value; } } } }
bool ModelLibrary::Load(Ogre::SceneManager* sc, string filename) { if (models) { for(int i = 0; i < models->size(); i++) { delete (*models)[i]; } delete models; } models = new vector<SModel*>(); TiXmlDocument doc(filename); if(doc.LoadFile()) { Ogre::LogManager::getSingleton().logMessage("XML: Models loaded"); } else { Ogre::LogManager::getSingleton().logMessage("XML: Foutje"); if(doc.Error()) { Ogre::LogManager::getSingleton().logMessage("XML: Fout"); Ogre::LogManager::getSingleton().logMessage(filename); Ogre::LogManager::getSingleton().logMessage(doc.ErrorDesc()); } return false; } TiXmlHandle hDoc(&doc); TiXmlElement* pElement; TiXmlHandle hRoot(0); pElement = hDoc.FirstChildElement().Element(); //Get the root element. // Check if the root element is correct. if( !(pElement->ValueStr() == XMLROOT) ) { Ogre::LogManager::getSingleton().logMessage("XML: Wrong root element"); return false; } hRoot = TiXmlHandle(pElement); // Store the root element. // Load models. ModelLibrary::LoadModelsFromXML(sc, pElement); return true; }
void playlist::load(std::string filename) { music.clear(); if (access(filename.c_str(), F_OK)==-1) { printf("No playlist found(%s). No music will played.\n", filename.c_str()); return; } TiXmlDocument doc(filename.c_str()); doc.LoadFile(); TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem=hDoc.FirstChildElement().Element(); // should always have a valid root but handle gracefully if it doesn't if (!pElem) { printf("Error opening: %s. No music will played.\n", filename.c_str()); return; } // printf("name: %s\n", pElem->Value()); hRoot=TiXmlHandle(pElem); TiXmlElement * songs = hRoot.FirstChild().Element(); for (; songs!=NULL; songs=songs->NextSiblingElement()) { const char *pKey=songs->Value(); const char *pText=songs->GetText(); if (!pKey || !pText) continue; // printf("loop: %s %s\n", pKey, pText); std::string file = pText; std::string disp; // songs->QueryStringAttribute("display", &disp); if (songs->QueryStringAttribute("display", &disp)!= TIXML_SUCCESS) disp = file; // printf("%s: %s\n", disp.c_str(), file.c_str()); if (access(file.c_str(), F_OK)==-1) { //no file found } else { music.push_back(std::make_pair(disp, file)); } } }
bool FontDef::loadFromFile(const char* path) { TiXmlDocument doc(path); if (!doc.LoadFile(TIXML_ENCODING_UTF8)) return false; TiXmlHandle hDoc(&doc); TiXmlElement* elem; TiXmlHandle hRoot(0); // root elem = hDoc.FirstChildElement().Element(); // /Font hRoot = TiXmlHandle(elem); this->resourcePath = elem->Attribute("file"); for (elem = hRoot.FirstChild("Character").Element(); elem; elem = elem->NextSiblingElement()) { char value; int x; int y; int width; int height; int xOffset; int yOffset; int xAdvance; value = (char)atoi(elem->GetText()); elem->QueryIntAttribute("x", &x); elem->QueryIntAttribute("y", &y); elem->QueryIntAttribute("width", &width); elem->QueryIntAttribute("height", &height); elem->QueryIntAttribute("x-offset", &xOffset); elem->QueryIntAttribute("y-offset", &yOffset); elem->QueryIntAttribute("x-advance", &xAdvance); this->characters[value] = CharacterDef( value, x, y, width, height, xOffset, yOffset, xAdvance); } return true; }
/**------------------------------------------------------------------------------- Trajectory @brief @param filename @return ---------------------------------------------------------------------------------*/ Trajectory::Trajectory(const std::string& filename) { TiXmlDocument doc(filename.c_str()); if (doc.LoadFile()) { TiXmlHandle hDoc(&doc); TiXmlElement* el = hDoc.FirstChild("TRAJECTORY").Element(); if (el) { mFilename = (el->Attribute("filename")) ? el->Attribute("filename") : ""; } } }
void GDMeshAttribute::OpenXML(const char* fileName) { TiXmlDocument doc(fileName); if(!doc.LoadFile()) return; TiXmlHandle hDoc(&doc); TiXmlElement* elementPtr; TiXmlHandle hRoot(0); elementPtr = hDoc.FirstChildElement().Element(); ReadXML(elementPtr); }
bool RosGContainerPublisher::readXMLFile(const std::string& fileName) { TiXmlDocument doc(fileName); if (!doc.LoadFile()) { _log->error("Could not load XML file '%v'", fileName); return false; } TiXmlHandle hDoc(&doc); TiXmlElement* element; TiXmlHandle hRoot(0); // find root element { element = hDoc.FirstChildElement().Element(); // should always have a valid root but handle gracefully if it does if (!element || strcmp("templates", element->Value()) != 0) { _log->error("Root element should be 'templates' but is '%v' in file '%v'", element->Value(), fileName); return false; } // save this for later hRoot = TiXmlHandle(element); } for (TiXmlElement* cElement = hRoot.FirstChildElement().Element(); cElement; cElement = cElement->NextSiblingElement()) { const char *child = cElement->Value(); if (!child) { _log->error("Invalid child '%v' of operations", child); return false; } else if (strcmp("template", child) == 0) { bool result = this->readTemplate(cElement); } else { _log->warn("Unknown child '%v', will be ignored", child); } } return true; }
void ConvertFromOM( char* inputFileName, MathObj* obj ) { IdCollection ids; LoadIdTable( &ids ); TiXmlDocument doc; doc.LoadFile( inputFileName ); TiXmlHandle hDoc( &doc ); TiXmlElement* pElem; pElem = hDoc.FirstChildElement().Element(); ConvertElemToObj(&ids, pElem, obj ); }
int main() { TiXmlDocument doc; doc.LoadFile("config.xml"); TiXmlHandle hDoc(&doc); //access root node TiXmlElement* pRoot = hDoc.FirstChildElement().Element(); if (!pRoot) return 0; //search childe node step by step from starting root node searchXMLData(pRoot); return 0; }
bool includeFile(SpriteNode* node, TiXmlElement* includeNode, SpriteBlock* &oldSibling) { // get path... ugly char configfilepath[FILENAME_BUFFERSIZE] = {0}; const char* documentRef = getDocument(includeNode); if (!getLocalFilename(configfilepath,includeNode->Attribute("file"),documentRef)) { return false; } ALLEGRO_PATH * incpath = al_create_path(configfilepath); al_append_path_component(incpath, "include"); TiXmlDocument doc( al_path_cstr(incpath, ALLEGRO_NATIVE_PATH_SEP) ); al_destroy_path(incpath); bool loadOkay = doc.LoadFile(); TiXmlHandle hDoc(&doc); TiXmlElement* elemParent; if(!loadOkay) { contentError("Include failed",includeNode); WriteErr("File load failed: %s\n",configfilepath); WriteErr("Line %d: %s\n",doc.ErrorRow(),doc.ErrorDesc()); return false; } elemParent = hDoc.FirstChildElement("include").Element(); if( elemParent == NULL) { contentError("Main <include> node not present",&doc); return false; } TiXmlElement* elemNode = elemParent->FirstChildElement(); if (elemNode == NULL) { contentError("Empty include",elemParent); return false; } while (elemNode) { if (!readNode(node, elemNode, elemParent, oldSibling)) return false; elemNode = elemNode->NextSiblingElement(); } return true; }