コード例 #1
0
TestData readXMLDoc() {

    XMLDocument doc;
#ifdef WIN32
    XMLCheckResult(doc.LoadFile("../../test/mpw_tests.xml"));
#else
    XMLCheckResult(doc.LoadFile("mpw_tests.xml"));
#endif

    TestData data;
    XMLNode * pRoot = doc.FirstChild();
    if (pRoot == 0) return data;

    XMLElement * pListElement = pRoot->FirstChildElement("case");
    TestData testData;

    while (pListElement != 0) {
        //We have a test case. Allocate memory for it.
        TestCase testCase;

        //Get the ID of this case
        std::string id = pListElement->Attribute("id");
        std::cout << "ID: " << id << std::endl;

        //Now check if we have a parent.
        const char* pParent = pListElement->Attribute("parent");
        if (pParent) {
            testCase = testData.at(pParent);
        }

        //Now fill in the data from this node.
        XMLElement * pNodeListElement = pListElement->FirstChildElement();
        while (pNodeListElement != 0) {
            const char* name = pNodeListElement->Name();
            const char* value = pNodeListElement->GetText();
            if (value != 0) {
                testCase[name] = value;
                std::cout << name << ": " << testCase[name] << std::endl;
            }
            else {
                testCase[name] = "";
                std::cout << name << ": " << "null" << std::endl;
            }
            pNodeListElement = pNodeListElement->NextSiblingElement();
        }

        testData[id] = testCase;

        pListElement = pListElement->NextSiblingElement("case");
    }

    return testData;
}
コード例 #2
0
std::shared_ptr<RoadPatch::PatchArray> RoadPatch::loadPatches(const std::string& filename)
{
  XMLDocument doc;
  doc.LoadFile(filename.c_str());

  if (doc.Error())
    return nullptr;

  std::shared_ptr<PatchArray> arr = std::make_shared<PatchArray>();

  for (XMLElement* titleElement = doc.FirstChildElement(XML_TITLE_ELEMENT);
       titleElement != nullptr;
       titleElement = titleElement->NextSiblingElement(XML_TITLE_ELEMENT))
  {
    // Create new
    ConstPtr tmp = std::make_shared<RoadPatch>(titleElement);

    // Check for XML/Read error
    if (!tmp->good())
      return nullptr;

    // Save according to ID
    (*arr)[tmp->getPatchTypeInt()] = tmp;
  }

  return arr;
}
コード例 #3
0
ファイル: example.cpp プロジェクト: igorventorim/UFES
int readFile(string file)
{
	XMLDocument doc;
	doc.LoadFile(file.data());
	cout <<  file << "\n";
	if(!doc.ErrorID())
	{
		int raio_circulo;
		
		XMLElement* janela = doc.FirstChildElement("aplicacao")->FirstChildElement("janela");
		const char *titulo = janela->FirstChildElement("titulo")->GetText();
		janela->FirstChildElement( "largura" )->QueryIntText( &width );
		janela->FirstChildElement( "altura" )->QueryIntText( &height );
		janela->FirstChildElement("fundo")->QueryIntAttribute("corR",&corR_fundo);
		janela->FirstChildElement("fundo")->QueryIntAttribute("corG",&corG_fundo);
		janela->FirstChildElement("fundo")->QueryIntAttribute("corB",&corB_fundo);
		
		XMLElement* circulo = doc.FirstChildElement("aplicacao")->FirstChildElement("circulo");
		circulo->QueryIntAttribute( "raio", &raio_circulo);
		circulo->QueryIntAttribute("corR",&corR_circulo);
		circulo->QueryIntAttribute("corG",&corG_circulo);
		circulo->QueryIntAttribute("corB",&corB_circulo);
		

		title = std::string(titulo);
		radius = raio_circulo/(double)width;
	}else
	{
		cout << "Erro ao abrir o arquivo XML "<< file << "\n";
	}	
	return doc.ErrorID();
}
コード例 #4
0
ファイル: TMXSceneEncoder.cpp プロジェクト: 03050903/GamePlay
void TMXSceneEncoder::write(const EncoderArguments& arguments)
{
    XMLDocument xmlDoc;
    XMLError err;
    if ((err = xmlDoc.LoadFile(arguments.getFilePath().c_str())) != XML_NO_ERROR)
    {
        LOG(1, "Call to XMLDocument::LoadFile() failed.\n");
        LOG(1, "Error returned: %d\n\n", err);
        return;
    }
    
    // Parse the Tiled map
    TMXMap map;
    string inputDirectory = arguments.getFileDirPath();

    LOG(2, "Parsing .tmx file.\n");
    if (!parseTmx(xmlDoc, map, inputDirectory))
    {
        return;
    }

    // Apply a gutter, or skirt, around the tiles to prevent gaps
    if (arguments.generateTextureGutter())
    {
        LOG(2, "Bulding gutter tilesets.\n");
        buildTileGutter(map, inputDirectory, arguments.getOutputDirPath());
    }

    // Write the tile map
    string fileName = arguments.getFileName();
    int pos = fileName.find_last_of('.');

    LOG(2, "Writing .scene file.\n");
    writeScene(map, arguments.getOutputFilePath(), (pos == -1 ? fileName : fileName.substr(0, pos)));
}
コード例 #5
0
void CSimulator::_configureVisu ( void ){
	if ( m_sSimCnf.pcPlotter )
		delete m_sSimCnf.pcPlotter;				
	m_sSimCnf.pcPlotter = new CPlotter ( );
	XMLDocument conf;
    	conf.LoadFile( m_sSimCnf.sParamsFile.c_str() );
	XMLElement* root = conf.FirstChildElement();
	string  elemName , attr;	
	for( XMLElement* elem = root->FirstChildElement() ; elem != NULL ; elem = elem->NextSiblingElement() ){
		elemName = elem->Value();
		if ( elemName == "Visualization" ){
			attr       = elem->Attribute("rf_rate");
			m_sSimCnf.pcPlotter->setRefreshRate ( atoi( attr.c_str() ) );
			int cnt = 0;
			int type;
			for( XMLElement* e = elem->FirstChildElement() ; e != NULL ; e = e->NextSiblingElement() ){
				attr  = e->Attribute("title");
				m_sSimCnf.pcPlotter->createDisplay ( NULL , NULL , 1 , attr );
				attr   = e->Attribute("x_lng");
				m_sSimCnf.pcPlotter->setXrange     ( cnt , atoi( attr.c_str() ) , "Time [k]" );
				int y_ini, y_end;
				attr   = e->Attribute("y_ini");
				y_ini  = atoi( attr.c_str() );
				attr   = e->Attribute("y_end");
				y_end  = atoi( attr.c_str() );
				m_sSimCnf.pcPlotter->setYrange     ( cnt , y_ini , y_end , "Power (W)" );
				cnt++;				
			}			
		}
	}
	conf.Clear();
	return;
};
コード例 #6
0
ファイル: XMLHandler.cpp プロジェクト: noxshroom/TikoIrcBot
string XMLHandler::LoadLink(string name)
{
    XMLDocument doc;
    doc.LoadFile("links.xml");
    if( doc.Error() )
    {
        cout << "\nERROR:" << doc.ErrorID() << endl;
        return "ERROR";
    }

    XMLElement* rootNode = doc.FirstChildElement("Links");
    if (!rootNode) std::cout << "No Links element" << std::endl;

    XMLElement* linkNode = rootNode->FirstChildElement("Link");
    if(!linkNode) std::cout << "No link elements" << std::endl;

    // Loop through XML
    for( ; linkNode != NULL; linkNode = linkNode->NextSiblingElement() )
    {
        if( name == linkNode->Attribute("name") )
        {
            return linkNode->Attribute("url");
        }
    }

    return "NOTFOUND";
}
コード例 #7
0
ファイル: xmlReader.cpp プロジェクト: github188/msm
void XmlReader::xmlReadContactInfo(void)
{
    XMLDocument doc;
    doc.LoadFile(m_filename);
    if (doc.ErrorID() != 0) {
        printf("read xml error!\n");
        return;
    }
    XMLElement *root = doc.FirstChildElement("root");

    XMLElement *contacts = root->FirstChildElement("contacts");
    for (XMLElement *contact = contacts->FirstChildElement("contact");
         contact;
         contact = contact->NextSiblingElement("contact")) {
        XMLElement *user2_id = contact->FirstChildElement("user_id");
        XMLElement *user2_account = contact->FirstChildElement("user_acount");
        XMLElement *user2_name = contact->FirstChildElement("user_name");

        printf("user_id: %s\n", user2_id->GetText());
        printf("user_account: %s\n",  user2_account->GetText());
        printf("user_name: %s\n", user2_name->GetText());
        printf("\n");
    }

}
コード例 #8
0
ファイル: tilemap.cpp プロジェクト: zkl/Gear
bool TileMap::load(const char * file)
{
	this->clear();

	XMLDocument document;
	document.LoadFile(file);
	XMLElement * root = document.FirstChildElement("map");
	if(root != 0)
	{
		// base path
		strcpy(_basePath, file);
		char* p = &_basePath[strlen(file)-1];
		while(p != _basePath && *p != '/')
			p--;

		if(*p == '/')
			*p = 0;

		analyzeMapInfo(root);
		for(XMLElement* e = root->FirstChildElement(); e != 0; e = e->NextSiblingElement())
		{
			if(e->Value() == std::string("tileset"))
				this->analyzeTileset(e);
			else if(e->Value() == std::string("layer"))
				this->anylyzeLayers(e);
			else if(e->Value() == std::string("imagelayer"))
				this->anylyzeImageLayer(e);
		}
		return true;
	}
	return false;
}
コード例 #9
0
ファイル: TracksXml.cpp プロジェクト: martinkg/stuntrally
bool ReverbsXml::LoadXml(string file)
{
    XMLDocument doc;
    XMLError e = doc.LoadFile(file.c_str());
    if (e != XML_SUCCESS)  return false;

    XMLElement* root = doc.RootElement();
    if (!root)  return false;

    //  clear
    revs.clear();
    revmap.clear();


    //  base
    XMLElement* b = root->FirstChildElement("base");
    if (b)
        GetParams(b, base);

    ///  revs
    int i=1;  //0 = none
    XMLElement* n = root->FirstChildElement("rev");
    while (n)
    {
        ReverbSet r;
        GetParams(n, r);

        revs.push_back(r);
        revmap[r.name] = i++;
        n = n->NextSiblingElement("rev");
    }
    return true;
}
コード例 #10
0
bool FractalConfiguration::readFractalID(string filename, string *id, string *error)
{
	XMLDocument doc;

	// Parse file
	doc.LoadFile(filename.c_str());

	if(doc.Error())
	{
		*error = doc.GetErrorStr1();
		return true;
	}

	// Get ID
	XMLElement *root = doc.RootElement();
	string name = string(root->Name());

	if(name != "fractal")
	{
		*error = "Configuration file is invalid!";
		return true;
	}

	const char* id_tmp = root->Attribute("id");

	if(id_tmp == NULL)
	{
		*error = "Configuration file is invalid!";
		return true;
	}

	*id = string(id_tmp);
	return false;
}
コード例 #11
0
ファイル: oscillator.cpp プロジェクト: mccagigal/mufco
COscillator::COscillator ( string* sParamsFile , int nID ){ 
	m_nID       = nID;
	// Configuration from XML
	XMLDocument conf;
    	conf.LoadFile( sParamsFile->c_str() );
	XMLElement* root = conf.FirstChildElement();
	string elemName , attr;	
	for( XMLElement* elem = root->FirstChildElement() ; elem != NULL ; elem = elem->NextSiblingElement() ){
		elemName = elem->Value();
		if ( elemName == "Oscilators" ){
			attr       = elem->Attribute("distribution");
			m_nIniDist = atoi( attr.c_str() );
			attr       = elem->Attribute("N");
			m_fN       = atof( attr.c_str() );
			attr       = elem->Attribute("offset");
			m_fOffset  = atof( attr.c_str() );
			for( XMLElement* e = elem->FirstChildElement() ; e != NULL ; e = e->NextSiblingElement() ){
				elemName = e->Value();
				if ( elemName == "coupling" ){
					attr     = e->Attribute("type");
					m_nKType = atoi( attr.c_str() );
					attr     = e->Attribute("K");
					m_fK     = atof( attr.c_str() );
				}
				else if ( elemName == "switching" ){
					attr     = e->Attribute("type");
					m_nPType = atoi( attr.c_str() );
					attr     = e->Attribute("P");
					m_fP     = atof( attr.c_str() );										
				}
			}							
		}
	}
	return;
};
コード例 #12
0
ファイル: MapLoader.cpp プロジェクト: nonconforme/glPortal
/**
 * Get a scene from a map file in XML format.
 */
Scene* MapLoader::getScene(const std::string &path) {
  scene = new Scene();
  // FIXME: shall we init player here? Probably not, and do it ONCE.
  scene->player.addComponent<Transform>();
  scene->player.addComponent<PlayerMotion>();
  scene->player.addComponent<Health>();
  scene->player.addComponent<SoundSource>();
  scene->player.addComponent<SoundListener>();

  XMLDocument doc;
  XMLError error = doc.LoadFile((Environment::getDataDir() + "/maps/" + path + ".xml").c_str());

  if (error == XML_NO_ERROR) {
    XMLHandle docHandle(&doc);
    XMLElement *element = docHandle.FirstChildElement().ToElement();
    rootHandle = XMLHandle(element);

    extractMaterials();
    extractSpawn();
    extractDoor();
    extractModels();
    extractLights();
    extractWalls();
    extractAcids();
    extractTriggers();
    System::Log(Info) << "Map " << path << " loaded";
  } else {
    System::Log(Error) << "Failed to load map " << Environment::getDataDir() << "/" << path << ".xml";
  }
  return scene;
}
コード例 #13
0
ファイル: environment.cpp プロジェクト: mccagigal/mufco
void CEnvironment::_configureSinusoidal ( void ){ 	
	/* Read components from XML file */
	XMLDocument conf;
    	conf.LoadFile( m_sSourceFile.c_str() );
	XMLElement* root = conf.FirstChildElement();
	string   elemName, attr;
	SFreqCmp tmp_FC;
	for( XMLElement* elem = root->FirstChildElement() ; elem != NULL ; elem = elem->NextSiblingElement() ){
		elemName = elem->Value();
		if ( elemName == "Cmp" ){
			attr          = elem->Attribute("period");
			tmp_FC.period = atof( attr.c_str() ) / float ( m_nSampling );
			attr          = elem->Attribute("phase");
			tmp_FC.phs    = atof( attr.c_str() );
			attr          = elem->Attribute("amplitude");
			tmp_FC.amp    = m_fAmplitude * atof( attr.c_str() );
			if ( tmp_FC.period > 0.0 ){
				m_vInputSignal [ int ( float( m_nFFTsize  ) / tmp_FC.period ) ] = tmp_FC;
				m_vNCAmp       [ int ( float( m_nFFTsize  ) / tmp_FC.period ) ] = tmp_FC.amp;
			}
			else{
				m_vInputSignal [ 0 ] = tmp_FC;
				m_vNCAmp       [ 0 ] = tmp_FC.amp;

			}
		}
	}
	return;
};
コード例 #14
0
std::shared_ptr<Screen> XMLScreenLoader::loadScreen(const std::string &path) {
  std::shared_ptr<Screen> screen = std::make_shared<Screen>(); //setup screen pointer

  XMLDocument doc;
  XMLError error = doc.LoadFile(path.c_str()); //load in XML document

  if (error == 0){
    XMLHandle docHandle(&doc);
    XMLElement *element = docHandle.FirstChildElement("screen").ToElement();
    XMLHandle rootHandle = XMLHandle(element);

    //screen->textColor = loadTextColor(rootHandle);
    //screen->bgColor = loadbgColor(rootHandle);

    if (!loadText(rootHandle, &screen->text)) Util::Log(Error, "XMLScreenLoader") << "Failed to load text in " << path;
    if (!extractColor(element, &screen->color)) Util::Log(Error, "XMLScreenLoader") << "Failed to load color in " << path;
    //if (screen->bgColor.x == 0) Util::Log(Error, "XMLScreenLoader") << "Failed to find background color element in " << path;

    Util::Log(Debug, "XMLScreenLoader") << "Screen " << path << " loaded";

    return screen;
  } else {
    Util::Log(Error, "XMLScreenLoader") << "Failed to load screen " << path;
    return nullptr;
  }
}
コード例 #15
0
ファイル: parser.cpp プロジェクト: Helios-vmg/Xabin
Parser::MetaParserStatus Parser::load_xml(const char *file_path){
	using namespace tinyxml2;
	XMLDocument doc;
	{
		switch (doc.LoadFile(file_path)){
			case XML_SUCCESS:
				break;
			case XML_ERROR_FILE_NOT_FOUND:
				return MetaParserStatus::FILE_NOT_FOUND;
			case XML_ERROR_FILE_COULD_NOT_BE_OPENED:
			case XML_ERROR_FILE_READ_ERROR:
				return MetaParserStatus::FILE_ERROR;
			default:
				return MetaParserStatus::UNKNOWN_XML_ERROR;
		}
	}
	auto spec = doc.FirstChildElement();
	if (strcmp(spec->Name(), "spec"))
		return MetaParserStatus::MALFORMED_XML_STRUCTURE;

	try{
		this->parse(spec, this->state);
	}catch (const XmlAttributeNotFoundException &){
		return MetaParserStatus::MALFORMED_XML_STRUCTURE;
	}catch (const Parser::MetaParserStatus &status){
		return status;
	}
	return MetaParserStatus::SUCCESS;
}
コード例 #16
0
ファイル: Config.cpp プロジェクト: snosscire/Block-World
	void Config::loadFile(const string& path)
	{
		XMLDocument document;
		if (document.LoadFile(path.c_str()) == XML_NO_ERROR) {
			XMLElement* file = document.FirstChildElement("file");
			if (file) {
				XMLElement* config = file->FirstChildElement("config");
				
				while (config) {
					const char* name = config->Attribute("name");
					if (name) {
						     if (strcmp(name, "DefaultGravity") == 0)       config->QueryDoubleAttribute("value", &Config::DefaultGravity);
						else if (strcmp(name, "PlayerMoveSpeed") == 0)      config->QueryDoubleAttribute("value", &Config::PlayerMoveSpeed);
						else if (strcmp(name, "PlayerJumpSpeed") == 0)      config->QueryDoubleAttribute("value", &Config::PlayerJumpSpeed);
						else if (strcmp(name, "MaxCrosshairDistance") == 0) config->QueryDoubleAttribute("value", &Config::MaxCrosshairDistance);
						else if (strcmp(name, "MaxGibsOnScreen") == 0)      config->QueryUnsignedAttribute("value", &Config::MaxGibsOnScreen);
						else if (strcmp(name, "GibsMin") == 0)              config->QueryIntAttribute("value", &Config::GibsMin);
						else if (strcmp(name, "GibsMax") == 0)              config->QueryIntAttribute("value", &Config::GibsMax);
						else if (strcmp(name, "BloodParticles") == 0)       config->QueryIntAttribute("value", &Config::BloodParticles);
						else if (strcmp(name, "GibMaxSpeedX") == 0)         config->QueryIntAttribute("value", &Config::GibMaxSpeedX);
						else if (strcmp(name, "GibMaxSpeedY") == 0)         config->QueryIntAttribute("value", &Config::GibMaxSpeedY);
						else if (strcmp(name, "BloodMaxSpeedX") == 0)       config->QueryIntAttribute("value", &Config::BloodMaxSpeedX);
						else if (strcmp(name, "BloodMaxSpeedY") == 0)       config->QueryIntAttribute("value", &Config::BloodMaxSpeedY);
					}
					
					config = config->NextSiblingElement("config");
				}
			}
		} else {
			cout << document.GetErrorStr1() << endl;
			cout << document.GetErrorStr2() << endl;
		}
	}
コード例 #17
0
ファイル: Scenario.cpp プロジェクト: smarmy/DungeonCrawler
Scenario::Scenario()
  : m_useCharGen(false),
    m_name("DPOC")
{
  XMLDocument doc;
  if (doc.LoadFile("Scenario.xml") != 0)
  {
    throw std::runtime_error{"Fatal error: no Scenario.xml file found!"};
  }

  TRACE("Loaded scenario file");

  XMLElement* root = doc.FirstChildElement("scenario");
  for (XMLElement* element = root->FirstChildElement(); element; element = element->NextSiblingElement())
  {
    std::string tagName = element->Name();

    if (tagName == "createParty")
    {
      m_useCharGen = std::string(element->GetText()) == "true";
    }
    else if (tagName == "name")
    {
      m_name = element->GetText();
    }
  }

  TRACE(" - m_gameName   = %s", m_name.c_str());
  TRACE(" - m_useCharGen = %s", m_useCharGen ? "true" : "false");
}
コード例 #18
0
ファイル: transport_config.cpp プロジェクト: billypu/mudgame
int CTransportConfig::Initialize(const char* confname)
{
    if (m_transports.size() <= 0)
    {
        XMLDocument doc;
        if (doc.LoadFile(confname) != XML_NO_ERROR)
        {
            throw CMudException("load xml transports config file failed");
        }
        
        XMLHandle docHandle(&doc);
        XMLHandle current_handle = docHandle.FirstChildElement("config").FirstChildElement("transports").FirstChild();
        XMLElement* elem = current_handle.ToElement();
        while (elem)
        {
            int id = elem->IntAttribute("id");
            m_transports[id].id = id;
            m_transports[id].name = elem->Attribute("name");
            m_transports[id].x = elem->IntAttribute("x");
            m_transports[id].y = elem->IntAttribute("y");
            m_transports[id].enabled = elem->BoolAttribute("enabled");

            STDOUT_DEBUG("id=%d, name=%s, x=%d, y=%d, enabled=%d", 
                    id, m_transports[id].name.c_str(), m_transports[id].x, m_transports[id].y, m_transports[id].enabled);
            elem = current_handle.NextSibling().ToElement();
        }
    }

    return 0;
}
コード例 #19
0
ファイル: xmlReader.cpp プロジェクト: github188/msm
void XmlReader::xmlReadSelfInfo(void)
{
    XMLDocument doc;
    doc.LoadFile(m_filename);
    if (doc.ErrorID() != 0) {
        printf("read xml error!\n");
        return;
    }
    XMLElement *root = doc.FirstChildElement("root");

    XMLElement *user = root->FirstChildElement("user");
    XMLElement *user_id = user->FirstChildElement("user_id");
    XMLElement *user1_account = user->FirstChildElement("user_acount");
    XMLElement *user_name = user->FirstChildElement("user_name");
    XMLElement *big_visit_num = user->FirstChildElement("big_visit_num");
    XMLElement *vsp_id = user->FirstChildElement("vsp_id");
    XMLElement *vsp_name = user->FirstChildElement("vsp_name");

    printf("user_id: %s\n", user_id->GetText());
    printf("user1_account: %s\n", user1_account->GetText());
    printf("user_name: %s\n", user_name->GetText());
    printf("big_visit_num: %s\n", big_visit_num->GetText());
    printf("vsp_id: %s\n", vsp_id->GetText());
    printf("vsp_name: %s\n", vsp_name->GetText());
    printf("================================================\n");
}
コード例 #20
0
ファイル: ConfigSingleton.cpp プロジェクト: ndoxx/BinnoBot
void ConfigSingleton::configure(std::string xml_file_path)
{
    //Open XML config file and try to load it
    XMLDocument doc;
    if(doc.LoadFile(xml_file_path.c_str()) != XML_SUCCESS)
    {
        std::cerr << "Cannot reach configuration file: " << xml_file_path << "!" << std::endl;
        return;
    }

    //Look for <config> element
    XMLElement* pConfig = doc.FirstChildElement("root")->FirstChildElement("config");
    if(pConfig==nullptr)
    {
        std::cerr << "Invalid configuration file: " << xml_file_path << "!" << std::endl;
        return;
    }

    //Iterate attribute list and set parameter values
    //Version 2 of TinyXML won't let me iterate over Attribute list this way by returning
    //const XMLAttribute*. I'm forced to const_cast before I find an elegant way of doing this.
    XMLAttribute* pAttrib = const_cast<XMLAttribute*>(pConfig->FirstAttribute());
    while(pAttrib != nullptr)
    {
        set_parameter(pAttrib->Name(),pAttrib->Value());
        pAttrib = const_cast<XMLAttribute*>(pAttrib->Next());
    }
}
コード例 #21
0
void Partida::cargarNiveles() {
	XMLDocument doc;
	// abro XML correspondiente al mundo
	bool cargoArchivo = doc.LoadFile(this->rutaMundo);
	// Si no se cargo, lanzo error.
	if (cargoArchivo == false) {
		std::cout << "\tError al abrir el archivo XML." << std::endl;
		return;
	}

	// obtengo nodos 'Niveles'
	const XMLNode* nodo = doc.RootElement();
	nodo = nodo->FirstChildElement("Niveles");

	// Inicializo el contador de niveles
	int i = 1;
	// Cargo el primer nodo de nivel
	const XMLNode* nodoNivel = nodo->FirstChildElement("Nivel");
	// Mientras el nodo de nivel no es nulo, cargo los niveles.
	while (nodoNivel != 0) {
		// Obtengo el nodo con la ruta de archivo del nivel.
		const XMLNode* nodoRuta = nodoNivel->FirstChildElement("Ruta");
		// Si el nodo ruta no es nulo, cargo el nivel en la tabla
		if (nodoRuta != 0) {
			this->idNiveles[i] = nodoRuta->GetText();
			i++;  // Incremento el contador de niveles cargados
		}
		nodoNivel = nodoNivel->NextSiblingElement("Nivel");
	}
}
コード例 #22
0
	//-----------------------------------------------------------------------
	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;
	}
コード例 #23
0
ファイル: main.cpp プロジェクト: davidkleiven/CompPhys2UIO
unsigned int parseInput(const string &fname)
{
  XMLDocument doc;
  XMLError status = doc.LoadFile(fname.c_str());
  if (status) return status;

  XMLElement* root = doc.FirstChildElement( "Document" );
  for (XMLElement* elm=root->FirstChildElement( "Dataset" ); elm != NULL; \
  elm=elm->NextSiblingElement( "Dataset") )
  {
    XMLElement* fname = elm->FirstChildElement( "Filename" );
    if ( fname != NULL )
    {
      options.datafiles.push_back(fname->GetText());
    }
    else{
      options.datafiles.push_back("");
    }

    XMLElement* outfile = elm->FirstChildElement( "Outfile" );
    if ( outfile != NULL )
    {
      options.outfiles.push_back(outfile->GetText());
    }
    else
    {
      options.outfiles.push_back("");
    }
  }
}
コード例 #24
0
ファイル: Arena.cpp プロジェクト: BrunoAgrizzi/cg-tf
void Arena::readXMLArena(const char* path){
    cout << "Reading arena at: " << path << endl;
	XMLDocument doc;
	doc.LoadFile(path);

	XMLNode* svgObjs = doc.FirstChildElement("svg")->FirstChild();
	while(svgObjs != NULL){

		XMLElement * obj = svgObjs->ToElement();

		if(strcmp(obj->Attribute("id"),"Arena") == 0){
			this->arena = Rect(	atof(obj->Attribute("x")),
												atof(obj->Attribute("y")),
												atof(obj->Attribute("width")),
												atof(obj->Attribute("height")),
												obj->Attribute("fill"),
												atof(obj->Attribute("stroke-width")),
												obj->Attribute("stroke"),
												obj->Attribute("id"));
		}

		if(strcmp(obj->Attribute("id"),"PostoAbastecimento") == 0){
			this->postoAbastecimento = Rect(	atof(obj->Attribute("x")),
												atof(obj->Attribute("y")),
												atof(obj->Attribute("width")),
												atof(obj->Attribute("height")),
												obj->Attribute("fill"),
												atof(obj->Attribute("stroke-width")),
												obj->Attribute("stroke"),
												obj->Attribute("id"));
		}

		if(strcmp(obj->Attribute("id"),"Jogador") == 0){
			this->jogador = Circle(	atof(obj->Attribute("cx")),
									atof(obj->Attribute("cy")),
									atof(obj->Attribute("r")),
									obj->Attribute("fill"),
									obj->Attribute("id"));
		}

		if(strcmp(obj->Attribute("id"),"Inimigo") == 0){
			this->inimigos.push_back(Circle(	atof(obj->Attribute("cx")),
													atof(obj->Attribute("cy")),
													atof(obj->Attribute("r")),
													obj->Attribute("fill"),
													obj->Attribute("id")));
		}

		if(strcmp(obj->Attribute("id"),"ObjetoResgate") == 0){
			this->objetosResgate.push_back(Circle(	atof(obj->Attribute("cx")),
													atof(obj->Attribute("cy")),
													atoi(obj->Attribute("r")),
													obj->Attribute("fill"),
													obj->Attribute("id")));
		}

		svgObjs = svgObjs->NextSibling();
	}
    cout << "OK!" << endl;
}
コード例 #25
0
ファイル: xmltest.cpp プロジェクト: AlejandorLazaro/tinyxml2
int example_1()
{
	XMLDocument doc;
	doc.LoadFile( "resources/dream.xml" );

	return doc.ErrorID();
}
コード例 #26
0
Application::Application() :
_oldTime(0.0f),
_rotateLeft(false),
_rotateRight(false),
_phiAng(0.0f),
_rotateUp(false),
_rotateDown(false),
_thetaAng(0.0f),
_zoomIn(false),
_zoomOut(false),
_distance(20.f),
_offset(0.f)
{

	if( version == 1 ) {
		file = "../map_ny_cooper_triangle.osm";
	} else if( version == 2 ) {
		file = "../house_in_ny.osm";
	} else if( version == 3 ) {
		file = "../road_in_ny.osm";
	} else if( version == 4 ) {
		file = "../straight_road_only.osm";
	} else if( version == 5 ) {
		file = "../ny_center.osm";
	} else if( version == 6 ) {
		file = "../ny_center_small.osm";
	}


	XMLDocument doc;
	doc.LoadFile(file);
	worker = new MapWorker(doc);
	std::cout << "App loaded" << std::endl;
}
コード例 #27
0
ファイル: Object.cpp プロジェクト: meh2481/magichexagon
bool anim::fromXML(string sXMLFilename)
{
	//Load in the XML document
    XMLDocument* doc = new XMLDocument();
    int iErr = doc->LoadFile(sXMLFilename.c_str());
	if(iErr != XML_NO_ERROR)
	{
		errlog << "Error parsing XML file " << sXMLFilename << ": Error " << iErr << endl;
		delete doc;
		return false;
	}

	//Grab root element
    XMLElement* root = doc->FirstChildElement("anim");
    if(root == NULL)
	{
		errlog << "Error: No toplevel \"anim\" item in XML file " << sXMLFilename << endl;
		delete doc;
		return false;
	}
    
	//Read off animation elements
	for(XMLElement* elem = root->FirstChildElement(); elem != NULL; elem = elem->NextSiblingElement())
	{
		fromXMLElement(elem);
	}
	delete doc;
	return true;
}
コード例 #28
0
int pastelstitch_interpreter (const vector <string> &arguments, pastelstitch::StaticEnvironment &senv)
{
	int argc = arguments.size ();

	if (argc == 2 && arguments.at (1) == string ("--version")) {
		print_version ();
	} else if (argc == 2 && arguments.at (1) == string ("--help")) {
		print_usage ();
	} else if (2 <= argc) {
		XMLDocument document;
		XMLError error = document.LoadFile (arguments.at (1).c_str ());
		if (error != XML_NO_ERROR) {
			cerr << "Failed to open XML document \"" << arguments.at (1) << "\"" << endl;
			return 2;
		}

		auto program_arguments = make_shared <vector <string>> (arguments);
		auto get_number_of_program_arguments_operation
			= make_shared <pastelstitch::GetNumberOfProgramArgumentsOperation> ();
		get_number_of_program_arguments_operation->program_arguments = program_arguments;
		senv.add_primitive_operation (pastelstitch::CompoundVector ("getnumberofprogramarguments", "main"),
			get_number_of_program_arguments_operation);
		auto get_program_argument_operation
			= make_shared <pastelstitch::GetProgramArgumentOperation> ();
		get_program_argument_operation->program_arguments = program_arguments;
		senv.add_primitive_operation (pastelstitch::CompoundVector ("getprogramargument", "main"),
			get_program_argument_operation);

		return run (document, senv);
	} else {
		print_usage ();
		return 1;
	}
	return 0;
}
コード例 #29
0
void highscore::newHighScore(score *newHighScore)
{
    // SAVE NEW SCORE DIRECTLY INTO XML FILE
    // Load XML file
    char scoreStr[10];

    XMLDocument doc;
    XMLElement *nodeTransversal;
    doc.LoadFile("score.xml");

    // Write its child first
    XMLText *nameText = doc.NewText(newHighScore->readPlayerName().c_str());
    XMLElement *name = doc.NewElement("name");
    name->InsertEndChild(nameText);

    sprintf(scoreStr, "%d", newHighScore->readScore());
    XMLText *scoreText = doc.NewText(scoreStr);
    XMLElement *score = doc.NewElement("score");
    score->InsertEndChild(scoreText);

    // Create new node
    XMLElement* hs = doc.NewElement("hs");
    hs->InsertEndChild(name);
    hs->InsertEndChild(score);

    doc.InsertEndChild(hs);

    doc.SaveFile("score.xml");
}
コード例 #30
0
ファイル: Tiro.cpp プロジェクト: rbpimenta/CG-UFES-20152-TF
void Tiro::carregarInformacoes() {
	XMLDocument* doc = new XMLDocument();

	doc->LoadFile("tiro.svg");

	if (doc == NULL) {
		cout << "Problema ao abrir arquivo .svg\n";
		exit(1);
	}

	XMLElement* svg = doc->FirstChildElement("svg");
	if (svg == NULL) {
		cout
				<< "Erro na hora de encontrar Element 'svg'! Finalizando programa...\n";
		exit(1);
	}

	XMLElement* circleElem = svg->FirstChildElement("circle");
	if (circleElem == NULL) {
		cout
				<< "Erro na hora de encontrar Element 'circle'! Finalizando programa...\n";
		exit(1);
	}

	this->tiro->setValues(circleElem);
}