bool XMLLoader::clientXMLHasValidValues(TiXmlDocument xmlFile){
	TiXmlElement *connection = xmlFile.FirstChildElement(kClientTag)->FirstChildElement(kConnectionTag);
	const char* clientIP = connection->FirstChildElement(kIPTag)->GetText();
	struct sockaddr_in sa;
	int success = inet_pton(AF_INET, clientIP, &(sa.sin_addr));
	if (success != 1){
		this->logWriter->writeInvalidValueForElementInXML(kIPTag);
		return false;
	}

	const char *clientPort = connection->FirstChildElement(kIPTag)->NextSiblingElement(kPortTag)->GetText();
	std::stringstream portStrValue;
	portStrValue << clientPort;
	unsigned int portIntValue;
	portStrValue >> portIntValue;
	if (portIntValue <= 0 || portIntValue > kMaxNumberOfValidPort) {
		this->logWriter->writeInvalidValueForElementInXML(kPortTag);
		return false;
	}

	TiXmlElement *firstMessageElement = xmlFile.FirstChildElement(kClientTag)->FirstChildElement(kConnectionTag)->NextSiblingElement(kMessagesTag)->FirstChildElement(kMessageTag);
	for(TiXmlElement *message = firstMessageElement; message != NULL; message = message->NextSiblingElement(kMessageTag)) {
		const char *messageID = message->FirstChildElement(kMessageIDTag)->GetText();
		this->messageIDList.push_back(messageID);

		string messageType = stringFromChar(message->FirstChildElement(kMessageTypeTag)->GetText());
		if ((messageType.compare(kMessageTypeInt) != 0) && (messageType.compare(kMessageTypeString) != 0) && (messageType.compare(kMessageTypeChar) != 0) && (messageType.compare(kMessageTypeDouble) != 0)) {
			this->logWriter->writeInvalidValueForElementInXML(kMessageTypeTag);
			return false;
		}
	}

	return true;
}
	bool cOpenALSoundEnvironment::CreateFromFile(const tString &asFile)
	{
		tString strType;
		TiXmlDocument doc;
		if (!doc.LoadFile(asFile.c_str()))
			return false;

		TiXmlElement* pMain = doc.FirstChildElement("SoundEnvironment")->FirstChildElement("Main");
		if (pMain)
		{
			strType = pMain->Attribute("Type");
			mstrName = pMain->Attribute("Name");
		}


		float* pfTemp;

		TiXmlElement* pParams = doc.FirstChildElement("SoundEnvironment")->FirstChildElement("Parameters");

		if ( (pParams == NULL) || (strType.compare("OpenAL")!=0) )
		{
			doc.Clear();
			return false;
		}

		mfDensity = cString::ToFloat(pParams->Attribute("Density"),0);
		mfDiffusion = cString::ToFloat(pParams->Attribute("Diffusion"),0);
		mfGain = cString::ToFloat(pParams->Attribute("Gain"),0);
		mfGainHF = cString::ToFloat(pParams->Attribute("GainHF"),0);
		mfGainLF = cString::ToFloat(pParams->Attribute("GainLF"),0);
		mfDecayTime = cString::ToFloat(pParams->Attribute("DecayTime"),0);
		mfDecayHFRatio = cString::ToFloat (pParams->Attribute("DecayHFRatio"),0);
		mfDecayLFRatio = cString::ToFloat (pParams->Attribute("DecayLFRatio"),0);
		mfReflectionsGain = cString::ToFloat(pParams->Attribute("ReflectionsGain"),0);
		mfReflectionsDelay = cString::ToFloat(pParams->Attribute("ReflectionsDelay"),0);
		pfTemp = cString::ToVector3f(pParams->Attribute("ReflectionsPan"),cVector3f(0)).v;
		mfReflectionsPan[0] = pfTemp[0];
		mfReflectionsPan[1] = pfTemp[1];
		mfReflectionsPan[2] = pfTemp[2];
		mfLateReverbGain = cString::ToFloat(pParams->Attribute("LateReverbGain"),0);
		mfLateReverbDelay = cString::ToFloat(pParams->Attribute("LateReverbDelay"),0);
		pfTemp = cString::ToVector3f(pParams->Attribute("LateReverbPan"),cVector3f(0)).v;
		mfLateReverbPan[0] = pfTemp[0];
		mfLateReverbPan[1] = pfTemp[1];
		mfLateReverbPan[2] = pfTemp[2];
		mfEchoTime = cString::ToFloat(pParams->Attribute("EchoTime"),0);
		mfEchoDepth = cString::ToFloat(pParams->Attribute("EchoDepth"),0);
		mfModulationTime = cString::ToFloat(pParams->Attribute("ModulationTime"),0);
		mfModulationDepth = cString::ToFloat(pParams->Attribute("ModulationDepth"),0);
		mfAirAbsorptionGainHF = cString::ToFloat(pParams->Attribute("AirAbsorptionGainHF"),0);
		mfHFReference = cString::ToFloat(pParams->Attribute("HFReference"),0);
		mfLFReference = cString::ToFloat(pParams->Attribute("LFReference"),0);
		mfRoomRolloffFactor =cString::ToFloat(pParams->Attribute("RoomRolloffFactor"),0);
		mbDecayHFLimit = cString::ToInt(pParams->Attribute("DecayHFLimit"),0);

		doc.Clear();
		pParams = NULL;

		return true;
	}
mitk::NavigationDataSet::Pointer mitk::NavigationDataReaderXML::Read(std::string fileName)
{
  //save old locale
  char * oldLocale;
  oldLocale = setlocale( LC_ALL, 0 );

  //define own locale
  std::locale C("C");
  setlocale( LC_ALL, "C" );

  m_FileName = fileName;

  TiXmlDocument document;
  if ( !document.LoadFile(fileName))
  {
    mitkThrowException(mitk::IGTIOException) << "File '"<<fileName<<"' could not be loaded.";
  }

  TiXmlElement* m_DataElem = document.FirstChildElement("Version");
  if(!m_DataElem)
  {
    // for backwards compatibility of version tag
    m_DataElem = document.FirstChildElement("Data");
    if(!m_DataElem)
    {
      mitkThrowException(mitk::IGTIOException) << "Data element not found.";
    }

  }

  if (m_DataElem->QueryIntAttribute("Ver", &m_FileVersion) != TIXML_SUCCESS)
  {
    if (m_DataElem->QueryIntAttribute("version", &m_FileVersion) != TIXML_SUCCESS)
    {
      mitkThrowException(mitk::IGTIOException) << "Version not specified in XML file.";
    }
  }

  if (m_FileVersion != 1)
  {
    mitkThrowException(mitk::IGTIOException) << "File format version "<<m_FileVersion<<" is not supported.";
  }

  m_parentElement = document.FirstChildElement("Data");
  if(!m_parentElement)
  {
    mitkThrowException(mitk::IGTIOException) << "Data element not found.";
  }

  m_parentElement->QueryIntAttribute("ToolCount", &m_NumberOfOutputs);

  mitk::NavigationDataSet::Pointer navigationDataSet = this->ReadNavigationDataSet();

  //switch back to old locale
  setlocale( LC_ALL, oldLocale );

  return navigationDataSet;
}
Example #4
0
int NppFTP::LoadSettings() {
	int result = 0;

	char xmlPath[MAX_PATH];
	char * utf8Store = SU::TCharToCP(m_configStore, CP_ACP);
	strcpy(xmlPath, utf8Store);
	::PathCombineA(xmlPath, utf8Store, "NppFTP.xml");

	TiXmlDocument settingsDoc = TiXmlDocument(xmlPath);
	settingsDoc.LoadFile();

	strcpy(xmlPath, utf8Store);
	::PathCombineA(xmlPath, utf8Store, "Certificates.xml");
	SU::FreeChar(utf8Store);

	TiXmlDocument certificatesDoc = TiXmlDocument(xmlPath);
	certificatesDoc.LoadFile();

	TiXmlElement* ftpElem = settingsDoc.FirstChildElement("NppFTP");
	if (!ftpElem) {
		result = 1;
		return result;
	}

	m_ftpSettings->LoadSettings(ftpElem);

	TiXmlElement * profilesElem = ftpElem->FirstChildElement(FTPProfile::ProfilesElement);
	if (!profilesElem) {
		m_profiles.clear();
		result = 1;
	} else {
		m_profiles = FTPProfile::LoadProfiles(profilesElem);
		for(size_t i = 0; i < m_profiles.size(); i++) {
			m_profiles.at(i)->AddRef();
			m_profiles.at(i)->SetCacheParent(m_ftpSettings->GetGlobalCache());
		}
	}


	ftpElem = certificatesDoc.FirstChildElement("NppFTP");
	if (!ftpElem) {
		m_certificates.clear();
		result = 1;
	} else {
		TiXmlElement * dersElem = ftpElem->FirstChildElement(SSLCertificates::DERsElem);
		if (!dersElem) {
			m_certificates.clear();
			result = 1;
		} else {
			vDER derVect = SSLCertificates::LoadDER(dersElem);
			m_certificates = SSLCertificates::ConvertDERVector(derVect);
			SSLCertificates::FreeDERVector(derVect);
		}
	}

	return result;
}
Example #5
0
// Opens the specified XML file if it exists or creates a new one otherwise.
// Returns 0 on error.
TiXmlElement* GetXmlFile(wxFileName file, bool create /*=true*/, wxString* error /*=0*/)
{
	if (wxFileExists(file.GetFullPath()) && file.GetSize() > 0)
	{
		// File does exist, open it

		TiXmlDocument* pXmlDocument = new TiXmlDocument;
		pXmlDocument->SetCondenseWhiteSpace(false);
		if (!LoadXmlDocument(pXmlDocument, file.GetFullPath(), error))
		{
			delete pXmlDocument;
			return 0;
		}

		TiXmlElement* pElement = pXmlDocument->FirstChildElement("FileZilla3");
		if (!pElement)
		{
			if (pXmlDocument->FirstChildElement())
			{
				// Not created by FileZilla3
				delete pXmlDocument;

				if (error)
					*error = _("Unknown root element, the file does not appear to be generated by FileZilla.");
				return 0;
			}
			pElement = pXmlDocument->LinkEndChild(new TiXmlElement("FileZilla3"))->ToElement();
		}

		return pElement;
	}
	else
	{
		// File does not exist
		if (!create)
			return 0;
		
		// create new XML document
		TiXmlDocument* pXmlDocument = new TiXmlDocument();
		pXmlDocument->SetCondenseWhiteSpace(false);
		pXmlDocument->LinkEndChild(new TiXmlDeclaration("1.0", "UTF-8", "yes"));

		pXmlDocument->LinkEndChild(new TiXmlElement("FileZilla3"));

		if (!SaveXmlFile(file, pXmlDocument, 0))
		{
			delete pXmlDocument;
			return 0;
		}

		return pXmlDocument->FirstChildElement("FileZilla3");
	}
}
Example #6
0
bool CompareTrees(const TiXmlDocument & code, const TiXmlDocument & doc, std::string & errTxt)
{
  const TiXmlNode * dNode = doc.FirstChildElement();
  const TiXmlNode * cNode = code.FirstChildElement();
  if(dNode->ValueStr() != "crava")
    errTxt = "Error: Documentation tree corrupt.\n";
  if(cNode->ValueStr() != "crava")
    errTxt = "Error: Code tree corrupt.\n";
  if(errTxt == "")
    CompareBranches(dNode, cNode, errTxt);

  return(errTxt == "");
}
Example #7
0
void Properties::loadProperties(char* filename) {
	TiXmlDocument * doc = new TiXmlDocument();
	if (doc->LoadFile(filename, TIXML_ENCODING_UTF8)) {

		char *host = const_cast<char*>(doc->FirstChildElement()->GetText());
		char *port = const_cast<char*>(doc->FirstChildElement()->NextSiblingElement()->GetText());

		//get host pair
		this->properties.insert(std::pair<char*, char*>("host", host));

		//get port pair
		this->properties.insert(std::pair<char*, char*>("port", port));
	}
}
Example #8
0
TiXmlElement *COptions::GetXML()
{
	simple_lock lock(m_mutex);

	USES_CONVERSION;
	CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml");
	char* bufferA = T2A(xmlFileName);
	if (!bufferA) {
		return 0;
	}

	TiXmlDocument *pDocument = new TiXmlDocument;

	if (!pDocument->LoadFile(bufferA)) {
		delete pDocument;
		return NULL;
	}

	TiXmlElement* pElement = pDocument->FirstChildElement("FileZillaServer");
	if (!pElement) {
		delete pDocument;
		return NULL;
	}

	// Must call FreeXML
	m_mutex.lock();

	return pElement;
}
Example #9
0
bool COneCleanSetting::Load()
{
    bool retval = false;
    TiXmlDocument xmlDoc;
    const TiXmlElement *pXmlSetting = NULL;
    const TiXmlElement *pXmlStrings = NULL;
    const TiXmlElement *pXmlIntegers = NULL;
    const TiXmlElement *pXmlChild = NULL;
    KFilePath settingPath = KFilePath::GetFilePath(_Module.m_hInst);

    settingPath.RemoveFileSpec();
    settingPath.Append(L"cfg\\onekeyclean.xml");
    if (!xmlDoc.LoadFile(UnicodeToAnsi(settingPath.value()).c_str(), TIXML_ENCODING_UTF8))
        goto clean0;

    pXmlSetting = xmlDoc.FirstChildElement("setting");
    if (!pXmlSetting)
        goto clean0;

    pXmlStrings = pXmlSetting->FirstChildElement("strings");
    if (pXmlStrings)
    {
        pXmlChild = pXmlStrings->FirstChildElement("entry");
        while (pXmlChild)
        {
            std::string strName, strValue;

            strName = pXmlChild->Attribute("name");
            strValue = pXmlChild->Attribute("value");
            if (strcmp(strName.c_str(), "default_entrys") != 0)
            {
                m_vStringStore[strName] = Utf8ToUnicode(strValue);
            }

            pXmlChild = pXmlChild->NextSiblingElement("entry");
        }
    }

    pXmlIntegers = pXmlSetting->FirstChildElement("integers");
    if (pXmlIntegers)
    {
        pXmlChild = pXmlIntegers->FirstChildElement("entry");
        while (pXmlChild)
        {
            std::string strName;
            int nValue;

            strName = pXmlChild->Attribute("name");
            pXmlChild->QueryIntAttribute("value", &nValue);
            m_vIntegerStore[strName] = nValue;

            pXmlChild = pXmlChild->NextSiblingElement("entry");
        }
    }

    retval = true;

clean0:
    return retval;
}
Example #10
0
	void ConfigValues::Load(const std::string &filename)
	{
		TiXmlDocument doc;
		doc.LoadFile(Assets::GetContentPath() + filename);
		TiXmlElement *xmlValues = doc.FirstChildElement("config"); 
		if (xmlValues)
		{
			TiXmlElement *xmlValue = xmlValues->FirstChildElement("value");
			while (xmlValue)
			{
				std::string name = XMLReadString(xmlValue, "name");

				if (xmlValue->Attribute("float"))
					instance->floats[name] = XMLReadFloat(xmlValue, "float");

				if (xmlValue->Attribute("string"))
					instance->strings[name] = XMLReadString(xmlValue, "string");

				if (xmlValue->Attribute("int"))
					instance->ints[name] = XMLReadInt(xmlValue, "int");

				if (xmlValue->Attribute("bool"))
					instance->bools[name] = XMLReadBool(xmlValue, "bool");

				if (xmlValue->Attribute("vector2"))
					instance->vector2s[name] = XMLReadVector2(xmlValue, "vector2");

				xmlValue = xmlValue->NextSiblingElement("value");
			}
		}
	}
Example #11
0
void Artifact::UpdateStats(const std::string & spec)
{
#ifdef WITH_XML
    // parse artifacts.xml
    TiXmlDocument doc;
    const TiXmlElement* xml_artifacts = NULL;

    if(doc.LoadFile(spec.c_str()) &&
        NULL != (xml_artifacts = doc.FirstChildElement("artifacts")))
    {
	size_t index = 0;
        const TiXmlElement* xml_artifact = xml_artifacts->FirstChildElement("artifact");
        for(; xml_artifact && index < UNKNOWN; xml_artifact = xml_artifact->NextSiblingElement("artifact"), ++index)
        {
            int value;
	    artifactstats_t* ptr = &artifacts[index];

            xml_artifact->Attribute("disable", &value);
            if(value) ptr->bits |= ART_DISABLED;

            xml_artifact->Attribute("extra", &value);
	    if(value && !SkipExtra(index)) ptr->extra = value;

	    Artifact art(index);
        }
    }
    else
    VERBOSE(spec << ": " << doc.ErrorDesc());
#endif
}
Example #12
0
bool CXmlConfig::LoadConfig(const char* szRootNodeName,const char* szFileName)
{
	if( !szRootNodeName )
		GenErr("配置文件的根节点名称不能为NULL");


	TiXmlDocument XmlDoc;

	if( !XmlDoc.LoadFile( szFileName ) )
		return false;

	TiXmlElement* pRoot = XmlDoc.FirstChildElement( szRootNodeName );

	if( !pRoot )
	{
		ostringstream strm;
		strm<<"配置文件的根节点不是\""<<szRootNodeName<<"\"";
		GenErr( strm.str() );
	}	
	Clear();

	m_pRoot = static_cast<TiXmlElement*>( pRoot->Clone() );

	return true;
}
bool wxsItemResData::LoadInSourceMode()
{
    // TODO: Check if source / header files have required blocks of code

    TiXmlDocument Doc;
    if ( !TinyXML::LoadDocument(m_WxsFileName,&Doc)  )
    {
        Manager::Get()->GetLogManager()->DebugLog(F(_T("wxSmith: Error loading wxs file (Col: %d, Row:%d): ") + cbC2U(Doc.ErrorDesc()),Doc.ErrorCol(),Doc.ErrorRow()));
        return false;
    }

    TiXmlElement* wxSmithNode = Doc.FirstChildElement("wxsmith");
    if ( !wxSmithNode ) return false;

    TiXmlElement* Object = wxSmithNode->FirstChildElement("object");
    if ( !Object ) return false;

    /*
    if ( cbC2U(Object->Attribute("name")) != m_ClassName ) return false;
    if ( cbC2U(Object->Attribute("class")) != m_ClassType ) return false;
    */

    RecreateRootItem();
    if ( !m_RootItem ) return false;
    m_RootItem->XmlRead(Object,true,true);
    LoadToolsReq(Object,true,true);

    return true;
}
Example #14
0
Progress::Progress(void)
{
	Logger::DiagnosticOut() << "Loading progress record\n";
	//Load XML
	TiXmlDocument doc = TiXmlDocument("Progress.xml");
	doc.LoadFile();
	TiXmlElement* root = doc.FirstChildElement("Progress");
	if(root)
	{
		TiXmlElement* record = root->FirstChildElement("Record");
		int record_number = 0;
		while(record)
		{
			std::string filename = "";
			bool completed = false;
			bool error = false;
			error |= (record->QueryValueAttribute("Filename", &filename) != TIXML_SUCCESS);
			error |= (record->QueryValueAttribute("Completed", &completed) != TIXML_SUCCESS);
			if(error)
				Logger::DiagnosticOut() << "Error parsing record number: " << record_number << ". Possible data: Filename:" << filename << ", completed: " << completed << "\n";
			else
			{
				ProgressRecord pr;
				pr.completed = completed;
				progress_[filename] = pr;
			}
			record = record->NextSiblingElement("Record");
			record_number++;
		}
	}
}
std::string CInitializer::GetSettingFromFile(std::string file, const std::string& name)
{
    TiXmlDocument xmldoc;
    if (!xmldoc.LoadFile(file.c_str()))
        return "";

    TiXmlElement* main = xmldoc.FirstChildElement("FileZilla3");
    if (!main)
        return "";

    TiXmlElement* settings = main->FirstChildElement("Settings");
    if (!settings)
        return "";

    for (TiXmlElement* setting = settings->FirstChildElement("Setting"); setting; setting = setting->NextSiblingElement("Setting"))
    {
        const char* nodeVal = setting->Attribute("name");
        if (!nodeVal || strcmp(nodeVal, name.c_str()))
            continue;

        TiXmlNode* textNode = setting->FirstChild();
        if (!textNode || !textNode->ToText())
            continue;

        return mkstr(textNode->Value());
    }

    return "";
}
Example #16
0
void CreatureManager::loadCreatureBuffer(const std::string& buffer)
{
    TiXmlDocument doc;
    doc.Parse(buffer.c_str());
    if(doc.Error())
        stdext::throw_exception(stdext::format("cannot load creature buffer: %s", doc.ErrorDesc()));

    TiXmlElement* root = doc.FirstChildElement();
    if(!root || (root->ValueStr() != "monster" && root->ValueStr() != "npc"))
        stdext::throw_exception("invalid root tag name");

    std::string cName = root->Attribute("name");
    stdext::tolower(cName);
    stdext::trim(cName);
    stdext::ucwords(cName);

    CreatureTypePtr newType(new CreatureType(cName));
    for(TiXmlElement* attrib = root->FirstChildElement(); attrib; attrib = attrib->NextSiblingElement()) {
        if(attrib->ValueStr() != "look")
            continue;

        internalLoadCreatureBuffer(attrib, newType);
        break;
    }

    doc.Clear();
}
Example #17
0
BOOL CSoftUninstall::LoadPinYin()
{
	CDataFileLoader	loader;
	BkDatLibContent content;

	if(!loader.GetLibDatContent((_ksafePath + SOFT_PINYIN_DAT).c_str(), content))
		return FALSE;

	TiXmlDocument plugins;
	if(plugins.Parse((char*)content.pBuffer) == NULL)
		return FALSE;

	TiXmlHandle hRoot(plugins.FirstChildElement("fonts"));
	for(TiXmlElement *pElem = hRoot.FirstChildElement("font").Element(); pElem != NULL; pElem = pElem->NextSiblingElement())
	{
		LPCSTR pHan = pElem->Attribute("c");
		if(pHan == NULL) continue;

		PinYin pinyin;
		pinyin._whole = pElem->Attribute("p");
		pinyin._acronym = pElem->Attribute("s");

		_hashPinYin.insert(make_pair(pHan, pinyin));
	}

	return TRUE;
}
Example #18
0
bool TreeImportExport::importTreeList(std::map<DWORD_PTR, ImportModuleThunk> & moduleList, DWORD_PTR * addressOEP, DWORD_PTR * addressIAT, DWORD * sizeIAT)
{
	moduleList.clear();
	*addressOEP = *addressIAT = 0;
	*sizeIAT = 0;

	TiXmlDocument doc;
	if(!readXmlFile(doc, xmlPath))
	{
		Scylla::windowLog.log(L"Load Tree :: Error parsing xml %S: %S\r\n", doc.Value(), doc.ErrorDesc());
		return false;
	}

	TiXmlElement * targetElement = doc.FirstChildElement();
	if (!targetElement)
	{
		Sylla::windowLog.log(L"Load Tree :: Error getting first child element in xml %S\r\n", doc.Value());
		return false;
	}

	*addressOEP = ConvertStringToDwordPtr(targetElement->Attribute("oep_va"));
	*addressIAT = ConvertStringToDwordPtr(targetElement->Attribute("iat_va"));
	*sizeIAT = (DWORD)ConvertStringToDwordPtr(targetElement->Attribute("iat_size"));

	parseAllElementModules(targetElement, moduleList);

	return true;
}
Example #19
0
void data::__data_load(data_type_t<config_t>)
{
    TiXmlDocument doc;
    doc.LoadFile(user_defined_path_resolver("C:\\mmo4\\resources\\data\\mmo-database.xml"));
    TiXmlElement* root_node = doc.FirstChildElement("mmo-database");
    parse_config(root_node->FirstChildElement("config-list"));
}
Example #20
0
void Game::UpdateGlobalDefines(const std::string & spec)
{
#ifdef WITH_XML
    // parse profits.xml
    TiXmlDocument doc;
    const TiXmlElement* xml_globals = NULL;

    if(doc.LoadFile(spec.c_str()) &&
            NULL != (xml_globals = doc.FirstChildElement("globals")))
    {
        // starting_resource
        KingdomUpdateStartingResource(xml_globals->FirstChildElement("starting_resource"));
        // view_distance
        OverViewUpdateStatic(xml_globals->FirstChildElement("view_distance"));
        // kingdom
        KingdomUpdateStatic(xml_globals->FirstChildElement("kingdom"));
        // game_over
        GameOverUpdateStatic(xml_globals->FirstChildElement("game_over"));
        // whirlpool
        WhirlpoolUpdateStatic(xml_globals->FirstChildElement("whirlpool"));
        // heroes
        HeroesUpdateStatic(xml_globals->FirstChildElement("heroes"));
        // castle_extra_growth
        CastleUpdateGrowth(xml_globals->FirstChildElement("castle_extra_growth"));
        // monster upgrade ratio
        MonsterUpdateStatic(xml_globals->FirstChildElement("monster_upgrade"));
    }
    else
        VERBOSE(spec << ": " << doc.ErrorDesc());
#endif
}
Example #21
0
void RecordList::ReadData(){
  TiXmlDocument *Doc = NULL;
  TiXmlElement *root,*trecord,*data,*child;
  Doc = new TiXmlDocument(_filename);
  if( Doc->LoadFile() ){
    root =  Doc->FirstChildElement("Data");
    trecord = root->FirstChildElement("Record");
    for ( ; trecord != NULL; trecord = trecord->NextSiblingElement("Record")){
      GContainer::Container *record = new GContainer::Container();
      data = trecord->FirstChildElement();
      for(; data != NULL; data = data->NextSiblingElement()){
	std::string name = data->ValueStr();
	std::string val;
	if(data->GetText()){
	  val = data->GetText();
	}else{
	  // Currently I'm not adding the field if it contains
	  // no data.
	  // val = "";
	  continue;
	}
	std::string type;
	if(Type2Name::GetInstance().GetType(name,type)){
	  if(not record->AddElement(name,type,val)){
	    std::cout << "There was a problem adding "
		      << name << " type = "
		      << type << ", val  = "
		      << val << " number = "
		      << records.size() + 1 << std::endl;
	  }
	}
      }
      records.push_back(record);
      record = NULL;
    }
  }
  //  TEST
  // for(int i = 0; i < records.size(); i++){
  //   GContainer::Container *w = records[i];
  //   std::string name = "Description";
  //   std::string val;
  //   if(w->GetElement(name,val)){
  //     std::cout <<"VAL = "<< val << std::endl;    
  //   }
  // }
  // for(int i = 0; i<100;i++){
  //   std::vector<GContainer::Container *>::iterator itr;
  //   itr = records.begin();
  //   for( ; itr != records.end(); itr++){
  //     GContainer::Container *w = *itr;
  //     std::string name = "Notes";
  //     std::string val;
  //     if(w->GetElement(name,val)){
  // 	std::cout <<"val = "<< val << std::endl;
  //     }
  //   }
  // }
  //TEST
  delete Doc;
}
Example #22
0
void data::__data_load(data_type_t<interact_template_t>)
{
    TiXmlDocument document;
    document.LoadFile(user_defined_path_resolver("C:\\Users\\John\\Documents\\mmo-code\\resources\\data\\mmo-data.xml"));
    TiXmlElement* root_node = document.FirstChildElement("mmo-data");
    parse_interact_template(root_node->FirstChildElement("interact-template-list"));
}
Example #23
0
int CSqXml::Decode( const sqbind::stdString &sData, sqbind::CSqMulti *pOut, int bIndexed )
{_STT();

	if ( !sData.length() || !pOut )
		return 0;

	try
	{
		// Parse XML
		TiXmlDocument	xmlDoc;

#if !defined( oexUNICODE )
		if ( !xmlDoc.Parse( sData.c_str() ) )
#else
		if ( !xmlDoc.Parse( oexStrToMb( oex::std2oex( sData ) ).Ptr() ) )
#endif
			; // return 0;

		// Decode into array
		return _Decode( pOut, xmlDoc.FirstChildElement(), bIndexed );

	}
	catch( ... )
	{
		// Just flag an error
		oexERROR( 0, oexMks( oexT( "Exception while decoding XML string : " ), 
						sqbind::std2oex( sData ) ) );

	} // end catch

	return 0;
}
Example #24
0
MetadataConfigurationImpl * MetadataConfigurationImpl::getConfiguration (const char *pszXMLMetadataFields)
{
    if (pszXMLMetadataFields == nullptr) {
        return nullptr;
    }

    getConfiguration();

    // Parse XML document
    TiXmlDocument doc;
    doc.Parse (pszXMLMetadataFields);
    TiXmlElement *pRoot = doc.FirstChildElement (XML_METADATA_ELEMENT);
    if (pRoot == nullptr) {
        return nullptr;
    }
    int rc = _pINSTANCE->addCustomMetadata (pRoot);
    if (rc != 0) {
        checkAndLogMsg ("MetadataConfiguration::getConfiguration", Logger::L_SevereError,
                        "MetadataConfiguration could not be initialized correctly. returned %d\n", rc);
        delete _pINSTANCE;
        _pINSTANCE = nullptr;
    }

    return _pINSTANCE;
}
bool wxsItemResData::LoadInFileMode()
{
    TiXmlDocument Doc;
    if ( !TinyXML::LoadDocument(m_XrcFileName,&Doc) ) return false;

    TiXmlElement* Resource = Doc.FirstChildElement("resource");
    if ( !Resource ) return false;

    TiXmlElement* Object = Resource->FirstChildElement("object");
    while ( Object )
    {
        if ( cbC2U(Object->Attribute("name")) == m_ClassName ) break;
        Object = Object->NextSiblingElement("object");
    }

    if ( !Object ) return false;
    if ( cbC2U(Object->Attribute("class")) != m_ClassType ) return false;

    RecreateRootItem();
    if ( !m_RootItem ) return false;
    m_RootItem->XmlRead(Object,true,false);
    LoadToolsReq(Object,true,false);

    return true;
}
Example #26
0
void HouseManager::load(const std::string& fileName)
{
    try {
        TiXmlDocument doc;
        doc.Parse(g_resources.readFileContents(fileName).c_str());
        if(doc.Error())
            stdext::throw_exception(stdext::format("failed to load '%s': %s (House XML)", fileName, doc.ErrorDesc()));

        TiXmlElement *root = doc.FirstChildElement();
        if(!root || root->ValueTStr() != "houses")
            stdext::throw_exception("invalid root tag name");

        for(TiXmlElement *elem = root->FirstChildElement(); elem; elem = elem->NextSiblingElement()) {
            if(elem->ValueTStr() != "house")
                stdext::throw_exception("invalid house tag.");

            uint32 houseId = elem->readType<uint32>("houseid");
            HousePtr house = getHouse(houseId);
            if(!house)
                house = HousePtr(new House(houseId)), addHouse(house);

            house->load(elem);
        }
    } catch(std::exception& e) {
        g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what()));
    }
}
Example #27
0
void Game::loadHeroes()
{
    TiXmlDocument *document = new TiXmlDocument("res/Heroes.xml");
    if(!document->LoadFile(TIXML_ENCODING_UTF8))
    {
        std::cout << "Error! file .... ";
        return;
    }

    TiXmlElement *xml_resources = document->FirstChildElement("resources");
    if (xml_resources == nullptr)
        return;

    TiXmlElement *xml_hero = xml_resources->FirstChildElement("hero");
    if (xml_hero == nullptr)
        return;

    while(xml_hero != nullptr)
    {
        HeroTemplate *hero = new HeroTemplate();

        // resource load
        Resources resource;
        hero->setName(xml_hero->Attribute("name"));
        string atk_snd = xml_hero->Attribute("atk_snd");
        string skl_snd = xml_hero->Attribute("skl_snd");
        string texture = xml_hero->Attribute("texture");
        string image = xml_hero->Attribute("image");
        string image2 = xml_hero->Attribute("image2");
        resource.loadAttackSound(atk_snd);
        resource.loadSkillSound(skl_snd);
        resource.loadTexture(texture);
        resource.loadImage(image);
        resource.loadImage2(image2);

        hero->setResources(resource);

        // stats load
        int hp, dmg_min, dmg_max, init, cost;
        Kind kind;
        Element element;
        Actions actions;

        xml_hero->QueryIntAttribute("hp", &hp);
        xml_hero->QueryIntAttribute("dmg_min", &dmg_min);
        xml_hero->QueryIntAttribute("dmg_max", &dmg_max);
        kind = strToKind(xml_hero->Attribute("kind"));
        element = strToElement(xml_hero->Attribute("elem"));
        xml_hero->QueryIntAttribute("init", &init);
        strToActions(xml_hero->Attribute("skill"), &actions);
        xml_hero->QueryIntAttribute("cost", &cost);

        hero->setStats(Stats(HP(hp), Damage(dmg_min, dmg_max), Kind(kind), Element(element),
                             Initiative(init), actions, cost));

        heroes.push_back(hero);

        xml_hero = xml_hero->NextSiblingElement("hero");
    }
}
Example #28
0
bool CFanart::Unpack()
{
    TiXmlDocument doc;
    doc.Parse(m_xml.c_str());

    m_fanart.clear();
    m_url.Empty();

    TiXmlElement *fanart = doc.FirstChildElement("fanart");
    if (fanart)
    {
        m_url = fanart->Attribute("url");
        TiXmlElement *fanartThumb = fanart->FirstChildElement("thumb");
        while (fanartThumb)
        {
            SFanartData data;
            data.strImage = fanartThumb->GetText();
            data.strResolution = fanartThumb->Attribute("dim");
            data.strPreview = fanartThumb->Attribute("preview");
            if (data.strPreview.IsEmpty())
            {   // could be due to an old version in db - use old hardcoded method for now
                if (m_url.Equals("http://thetvdb.com/banners/"))
                    data.strPreview = "_cache/" + data.strImage;
            }
            ParseColors(fanartThumb->Attribute("colors"), data.strColors);
            m_fanart.push_back(data);
            fanartThumb = fanartThumb->NextSiblingElement("thumb");
        }
    }
    return true;
}
Example #29
0
void BuildingInfo::UpdateCosts(const std::string & spec)
{
#ifdef WITH_XML
    // parse buildings.xml
    TiXmlDocument doc;
    const TiXmlElement* xml_buildings = NULL;

    if(doc.LoadFile(spec.c_str()) &&
        NULL != (xml_buildings = doc.FirstChildElement("buildings")))
    {
	size_t index = 0;

        for(const TiXmlElement* xml_building = xml_buildings->FirstChildElement("building");
    		xml_building && BUILD_NOTHING != _builds[index].id2; xml_building = xml_building->NextSiblingElement("building"), ++index)
        {
    	    cost_t & cost = _builds[index].cost;
	    int value;

            xml_building->Attribute("gold", &value); cost.gold = value;
            xml_building->Attribute("wood", &value); cost.wood = value;
            xml_building->Attribute("mercury", &value); cost.mercury = value;
            xml_building->Attribute("ore", &value); cost.ore = value;
            xml_building->Attribute("sulfur", &value); cost.sulfur = value;
            xml_building->Attribute("crystal", &value); cost.crystal = value;
            xml_building->Attribute("gems", &value); cost.gems = value;
	}
    }
    else
    VERBOSE(spec << ": " << doc.ErrorDesc());
#endif
}
 bool loadRobotModel(ros::NodeHandle node_handle, urdf::Model &robot_model, std::string &root_name, std::string &tip_name, std::string &xml_string)
 {
   std::string urdf_xml,full_urdf_xml;
   node_handle.param("urdf_xml",urdf_xml,std::string("robot_description"));
   node_handle.searchParam(urdf_xml,full_urdf_xml);
   TiXmlDocument xml;
   ROS_DEBUG("Reading xml file from parameter server\n");
   std::string result;
   if (node_handle.getParam(full_urdf_xml, result))
     xml.Parse(result.c_str());
   else
   {
     ROS_FATAL("Could not load the xml from parameter server: %s\n", urdf_xml.c_str());
     return false;
   }
   xml_string = result;
   TiXmlElement *root_element = xml.RootElement();
   TiXmlElement *root = xml.FirstChildElement("robot");
   if (!root || !root_element)
   {
     ROS_FATAL("Could not parse the xml from %s\n", urdf_xml.c_str());
     exit(1);
   }
   robot_model.initXml(root);
   if (!node_handle.getParam("root_name", root_name)){
     ROS_FATAL("No root name found on parameter server");
     return false;
   }
   if (!node_handle.getParam("tip_name", tip_name)){
     ROS_FATAL("No tip name found on parameter server");
     return false;
   }
   return true;
 }