bool EntityLODComponent::LoadFromFile(const char *szFilename) { TiXmlDocument doc; if (!doc.LoadFile(szFilename,Vision::File.GetManager())) return false; return ParseXMLNode(XMLHelper::SubNode(doc.RootElement(),"LOD",false)); }
/**\brief Load an XML file * \arg filename The XML file that should be parsed. * \arg optional If this is true, an error is not returned if the file doesn't exist. */ bool Components::Load(string filename, bool optional) { xmlDocPtr doc; xmlNodePtr cur; int versionMajor = 0, versionMinor = 0, versionMacro = 0; int numObjs = 0; bool success = true; File xmlfile = File (filename); long filelen = xmlfile.GetLength(); char *buffer = xmlfile.Read(); doc = xmlParseMemory( buffer, static_cast<int>(filelen) ); delete [] buffer; if( doc == NULL ) { LogMsg(ERR, "Could not load '%s' for parsing.", filename.c_str() ); return optional; } cur = xmlDocGetRootElement( doc ); if( cur == NULL ) { LogMsg(ERR, "'%s' file appears to be empty.", filename.c_str() ); xmlFreeDoc( doc ); return false; } if( xmlStrcmp( cur->name, (const xmlChar *)rootName.c_str() ) ) { LogMsg(ERR, "'%s' appears to be invalid. Root element was %s.", filename.c_str(), (char *)cur->name ); xmlFreeDoc( doc ); return false; } else { LogMsg(INFO, "'%s' file found and valid, parsing...", filename.c_str() ); } cur = cur->xmlChildrenNode; while( success && cur != NULL ) { // Parse for the version information and any children nodes if( ( !xmlStrcmp( cur->name, BAD_CAST "version-major" ) ) ) { xmlChar *key = xmlNodeListGetString( doc, cur->xmlChildrenNode, 1 ); versionMajor = atoi( (char *)key ); xmlFree( key ); } else if( ( !xmlStrcmp( cur->name, BAD_CAST "version-minor" ) ) ) { xmlChar *key = xmlNodeListGetString( doc, cur->xmlChildrenNode, 1 ); versionMinor = atoi( (char *)key ); xmlFree( key ); } else if( ( !xmlStrcmp( cur->name, BAD_CAST "version-macro" ) ) ) { xmlChar *key = xmlNodeListGetString( doc, cur->xmlChildrenNode, 1 ); versionMacro = atoi( (char *)key ); xmlFree( key ); } else if( ( !xmlStrcmp( cur->name, BAD_CAST componentName.c_str() ) ) ) { // Parse a Component success = ParseXMLNode( doc, cur ); assert(success); if(success) numObjs++; } cur = cur->next; } xmlFreeDoc( doc ); LogMsg(INFO, "Parsing of file '%s' done, found %d objects. File is version %d.%d.%d.", filename.c_str(), numObjs, versionMajor, versionMinor, versionMacro ); return success; }
/**\brief Load an XML file * \arg filename The XML file that should be parsed. * \arg optional If this is true, an error is not returned if the file doesn't exist. */ bool Components::Load(string filename, bool optional) { xmlDocPtr doc; xmlNodePtr cur, ver; int versionMajor = 0, versionMinor = 0, versionMacro = 0; int numObjs = 0; bool success = true; File xmlfile = File (filename); long filelen = xmlfile.GetLength(); char *buffer = xmlfile.Read(); doc = xmlParseMemory( buffer, static_cast<int>(filelen) ); delete [] buffer; if( doc == NULL ) { LogMsg(ERR, "Could not load '%s' for parsing.", filename.c_str() ); return optional; } cur = xmlDocGetRootElement( doc ); if( cur == NULL ) { LogMsg(ERR, "'%s' file appears to be empty.", filename.c_str() ); xmlFreeDoc( doc ); return false; } if( xmlStrcmp( cur->name, (const xmlChar *)rootName.c_str() ) ) { LogMsg(ERR, "'%s' appears to be invalid. Root element was %s.", filename.c_str(), (char *)cur->name ); xmlFreeDoc( doc ); return false; } else { LogMsg(INFO, "'%s' file found and valid, parsing...", filename.c_str() ); } // Get the version number if( (ver = FirstChildNamed(cur, "version-major")) != NULL ) { versionMajor = NodeToInt(doc,ver); } if( (ver = FirstChildNamed(cur, "version-minor")) != NULL ) { versionMinor = NodeToInt(doc,ver); } if( (ver = FirstChildNamed(cur, "version-macro")) != NULL ) { versionMacro = NodeToInt(doc,ver); } if( ( versionMajor != EPIAR_VERSION_MAJOR ) || ( versionMinor != EPIAR_VERSION_MINOR ) || ( versionMacro != EPIAR_VERSION_MICRO ) ) { LogMsg(WARN, "File '%s' is version %d.%d.%d. This may cause problems since it does not match the current version %d.%d.%d.", filename.c_str(), versionMajor, versionMinor, versionMacro, EPIAR_VERSION_MAJOR, EPIAR_VERSION_MINOR, EPIAR_VERSION_MICRO ); } // Get the components cur = cur->xmlChildrenNode; while( success && cur != NULL ) { // Parse for the version information and any children nodes if( ( !xmlStrcmp( cur->name, BAD_CAST componentName.c_str() ) ) ) { // Parse a Component success = ParseXMLNode( doc, cur ); assert(success || optional); if(success) numObjs++; } cur = cur->next; } xmlFreeDoc( doc ); filepath = filename; LogMsg(INFO, "Parsing of file '%s' done, found %d objects. File is version %d.%d.%d.", filename.c_str(), numObjs, versionMajor, versionMinor, versionMacro ); return success; }