当前位置: 首页>>代码示例>>C++>>正文


C++ XMLDocument::GetErrorStr1方法代码示例

本文整理汇总了C++中XMLDocument::GetErrorStr1方法的典型用法代码示例。如果您正苦于以下问题:C++ XMLDocument::GetErrorStr1方法的具体用法?C++ XMLDocument::GetErrorStr1怎么用?C++ XMLDocument::GetErrorStr1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XMLDocument的用法示例。


在下文中一共展示了XMLDocument::GetErrorStr1方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadFile

	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;
		}
	}
开发者ID:snosscire,项目名称:Block-World,代码行数:33,代码来源:Config.cpp

示例2: readFractalID

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;
}
开发者ID:svenhertle,项目名称:fractalimages,代码行数:34,代码来源:FractalConfiguration.cpp

示例3: Init

// Loads the campaign data
int _Campaign::Init() {
	Campaigns.clear();

	Log.Write("_Campaign::Init - Loading file irrlamb.xml");

	// Open the XML file
	std::string LevelFile = std::string("levels/main.xml");
	XMLDocument Document;
	if(Document.LoadFile(LevelFile.c_str()) != XML_NO_ERROR) {
		Log.Write("Error loading level file with error id = %d", Document.ErrorID());
		Log.Write("Error string 1: %s", Document.GetErrorStr1());
		Log.Write("Error string 2: %s", Document.GetErrorStr2());
		Close();
		return 0;
	}

	// Check for level tag
	XMLElement *CampaignsElement = Document.FirstChildElement("campaigns");
	if(!CampaignsElement) {
		Log.Write("Could not find campaigns tag");
		return 0;
	}

	// Load campaigns
	XMLElement *CampaignElement = CampaignsElement->FirstChildElement("campaign");
	for(; CampaignElement != 0; CampaignElement = CampaignElement->NextSiblingElement("campaign")) {

		CampaignStruct Campaign;
		Campaign.Name = CampaignElement->Attribute("name");

		// Get levels
		XMLElement *LevelElement = CampaignElement->FirstChildElement("level");
		for(; LevelElement != 0; LevelElement = LevelElement->NextSiblingElement("level")) {
			LevelStruct Level;
			Level.File = LevelElement->GetText();
			Level.DataPath = Game.GetWorkingPath() + "levels/" + Level.File + "/";
			Level.Unlocked = 0;
			LevelElement->QueryIntAttribute("unlocked", &Level.Unlocked);

			::Level.Init(Level.File, true);
			Level.NiceName = ::Level.GetLevelNiceName();

			Campaign.Levels.push_back(Level);
		}

		Campaigns.push_back(Campaign);
	}

	return 1;
}
开发者ID:zimagic,项目名称:irrlamb,代码行数:51,代码来源:campaign.cpp

示例4: readXML

	void ImageMapWorldCreator::readXML(MapDirectory* mapDirectory, Engine* engine, SDL_Surface* surface, World* world)
	{
		XMLDocument document;
		if (document.LoadFile(mapDirectory->getXMLPath().c_str()) == XML_NO_ERROR) {
			XMLElement* mapElement = document.FirstChildElement("map");
			if (mapElement) {
				XMLElement* backgroundsElement = mapElement->FirstChildElement("backgrounds");
				XMLElement* texturesElement = mapElement->FirstChildElement("textures");
				if (texturesElement) {
					readTexturesElement(texturesElement, surface);
				}
				if (backgroundsElement) {
					readBackgroundsElement(backgroundsElement, engine, mapDirectory, world);
				}
			}
		} else {
			cout << document.GetErrorStr1() << endl;
			cout << document.GetErrorStr2() << endl;
		}
	}
开发者ID:snosscire,项目名称:Block-World,代码行数:20,代码来源:ImageMapWorldCreator.cpp

示例5: load_items

void load_items()
{
  static const std::string itemDatabase = config::res_path("Items.xml");

  XMLDocument doc;

  if (doc.LoadFile(itemDatabase.c_str()) != 0)
  {
    TRACE("Unable to open item database %s (%s)!", itemDatabase.c_str(), doc.GetErrorStr1());

    throw std::runtime_error("Unable to open item database " + itemDatabase);
  }

  const XMLElement* root = doc.FirstChildElement("items");
  for (const XMLElement* element = root->FirstChildElement(); element; element = element->NextSiblingElement())
  {
    Item item = parse_item_element(element);

    TRACE("Loaded new item %s", item.name.c_str());

    itemDefinitions.push_back(item);
  }
}
开发者ID:smarmy,项目名称:DPOC,代码行数:23,代码来源:Item.cpp

示例6: load_status_effects

void load_status_effects()
{
  static const std::string database = config::res_path("StatusEffects.xml");

  XMLDocument doc;
  if (doc.LoadFile(database.c_str()) != 0)
  {
    TRACE("Unable to open status database %s (%s)!", database.c_str(), doc.GetErrorStr1());

    throw std::runtime_error("Unable to open status database " + database);
  }

  const XMLElement* root = doc.FirstChildElement("statusEffects");

  for (const XMLElement* element = root->FirstChildElement(); element; element = element->NextSiblingElement())
  {
    StatusEffect status = parse_status_effect_element(element);

    TRACE("New statusEffect %s loaded.", status.name.c_str());

    statusEffects.push_back(status);
  }
}
开发者ID:smarmy,项目名称:DPOC,代码行数:23,代码来源:StatusEffect.cpp

示例7: XmlParsingException

void
Game::LoadMap( const std::string & filename )
{
  XMLDocument doc;
  doc.LoadFile(filename.c_str());


  if ( doc.ErrorID() != XML_NO_ERROR )
  {
    ostringstream ss;
    ss << "Loadfile:" << g_TinyXmlErrors[doc.ErrorID()] << " " << doc.GetErrorStr1() << " " << doc.GetErrorStr2();
    throw XmlParsingException(ss.str());

  }

  // Load rooms
  XMLElement *pElem = doc.FirstChildElement( "Room");
  
  while( pElem != NULL )
  {
    g_Log << "loading..." << pElem->Attribute("id");
    Room *pRoom  = NULL;
    // Custom rooms
    if ( pElem->Attribute("class")) 
    {
      std::string classID = pElem->Attribute("class");
      pRoom = RoomFactory::Create(classID);
    } 
    else 
    {
      pRoom = new Room();	
    }
    pRoom->Load( *pElem );
    if ( m_Rooms.find(pRoom->GetId()) != m_Rooms.end()) 
    {
      throw DuplicateRoomIdException(pRoom->GetId());
    }
    m_Rooms[pRoom->GetId()] = pRoom;
    pElem = pElem->NextSiblingElement("Room");
  }
  // Load transitions

  pElem = doc.FirstChildElement( "Transitions");
  if ( pElem != NULL ) 
  {
    pElem = pElem->FirstChildElement("Transition");
  
    while( pElem != NULL )
    {
      const char * from = pElem->Attribute("from");
      const char * to = pElem->Attribute("to");
      const char * direction = pElem->Attribute("direction");
      const char * oneway = pElem->Attribute("oneway");

      if ( direction == NULL ) throw AttributeMissingException("Direction is missing from transition");
      if ( from == NULL ) throw AttributeMissingException("From attribute is missing from transition!");
      if ( to == NULL )   throw AttributeMissingException("To attribute is missing from transition!");
    
      // check is from a proper id
      if ( m_Rooms.find(from) == m_Rooms.end() ) 
      { 
	ostringstream ss;
	ss << from << " is not a proper room id";
	throw InvalidAttributeException(ss.str());
      }
      // check is to a proper id
      if ( m_Rooms.find(to) == m_Rooms.end() ) 
      { 
	ostringstream ss;
	ss << to << " is not a proper room id";
	throw InvalidAttributeException(ss.str());
      }
      string tmp = direction;
      transform(tmp.begin(),tmp.end(), tmp.begin(), [] (char c){ return tolower(c);});    
      Direction dir = kNumDirs;
      if ( tmp == "east" ) dir = East;
      else if ( tmp == "north" ) dir = North;
      else if ( tmp == "south" ) dir = South;
      else if ( tmp == "west" ) dir = West;
      else throw InvalidAttributeException("Direction is not properly set");
   
      m_Rooms[from]->SetNextRoom(dir, m_Rooms[to]);
      if ( !oneway )
      {
	m_Rooms[to]->SetNextRoom(g_Opposite[dir], m_Rooms[from]);
      }
      pElem = pElem->NextSiblingElement("Transition");
    }
  } 
  else 
  {
    throw ElementMissingException("Transitions is missing!");
  }
  
  // set current room
  pElem = doc.FirstChildElement("OnStart");
  if ( pElem == NULL ) throw ElementMissingException("No OnStart defined");

  pElem = pElem->FirstChildElement("CurrentRoom");
  if ( pElem == NULL ) 
//.........这里部分代码省略.........
开发者ID:noxshroom,项目名称:SDL,代码行数:101,代码来源:Game.cpp

示例8: Init

// Loads a level file
int _Level::Init(const std::string &LevelName, bool HeaderOnly) {
	if(!HeaderOnly)
		Log.Write("_Level::Init - Loading level: %s", LevelName.c_str());
	
	// Get paths
	this->LevelName = LevelName;
	LevelNiceName = "";
	std::string LevelFile = LevelName + "/" + LevelName + ".xml";
	std::string FilePath = Game.GetWorkingPath() + std::string("levels/") + LevelFile;
	std::string CustomFilePath = Save.GetCustomLevelsPath() + LevelFile;
	std::string DataPath = Game.GetWorkingPath() + std::string("levels/") + LevelName + "/";

	// See if custom level exists first
	IsCustomLevel = false;
	std::ifstream CustomLevelExists(CustomFilePath.c_str());
	if(CustomLevelExists) {
		IsCustomLevel = true;
		FilePath = CustomFilePath;
		DataPath = Save.GetCustomLevelsPath() + LevelName + "/";
	}
	CustomLevelExists.close();

	// Open the XML file
	XMLDocument Document;
	if(Document.LoadFile(FilePath.c_str()) != XML_NO_ERROR) {
		Log.Write("Error loading level file with error id = %d", Document.ErrorID());
		Log.Write("Error string 1: %s", Document.GetErrorStr1());
		Log.Write("Error string 2: %s", Document.GetErrorStr2());
		Close();
		return 0;
	}

	// Check for level tag
	XMLElement *LevelElement = Document.FirstChildElement("level");
	if(!LevelElement) {
		Log.Write("Could not find level tag");
		Close();
		return 0;
	}

	// Level version
	if(LevelElement->QueryIntAttribute("version", &LevelVersion) == XML_NO_ATTRIBUTE) {
		Log.Write("Could not find level version");
		Close();
		return 0;
	}

	// Check required game version
	GameVersion = LevelElement->Attribute("gameversion");
	if(GameVersion == "") {
		Log.Write("Could not find game version attribute");
		Close();
		return 0;
	}

	// Load level info
	XMLElement *InfoElement = LevelElement->FirstChildElement("info");
	if(InfoElement) {
		XMLElement *NiceNameElement = InfoElement->FirstChildElement("name");
		if(NiceNameElement) {
			LevelNiceName = NiceNameElement->GetText();
		}
	}

	// Return after header is read
	if(HeaderOnly) {
		Close();
		return true;
	}

	// Load default lua script
	Scripts.clear();
	Scripts.push_back(Game.GetWorkingPath() + "scripts/default.lua");

	// Options
	bool Fog = false;
	bool EmitLight = false;
	Level.ClearColor.set(255, 0, 0, 0);

	// Load options
	XMLElement *OptionsElement = LevelElement->FirstChildElement("options");
	if(OptionsElement) {

		// Does the player emit light?
		XMLElement *EmitLightElement = OptionsElement->FirstChildElement("emitlight");
		if(EmitLightElement) {
			EmitLightElement->QueryBoolAttribute("enabled", &EmitLight);
		}
	}

	// Load world
	XMLElement *ResourcesElement = LevelElement->FirstChildElement("resources");
	if(ResourcesElement) {

		// Load scenes
		for(XMLElement *SceneElement = ResourcesElement->FirstChildElement("scene"); SceneElement != 0; SceneElement = SceneElement->NextSiblingElement("scene")) {

			// Get file
			std::string File = SceneElement->Attribute("file");
//.........这里部分代码省略.........
开发者ID:vinjn,项目名称:irrlamb,代码行数:101,代码来源:level.cpp

示例9: save

bool FractalConfiguration::save(string filename)
{
	if(invalidID())
		return true;

	// Check filename and append .xml
	if(!endsWith(filename, ".xml"))
		filename += ".xml";

	// Create document
	XMLDocument doc;

	// Root element
	XMLElement *root = doc.NewElement("fractal");
	root->SetAttribute("id", m_id.c_str());
	doc.InsertEndChild(root);

	// Add properties
	iterate();

	while(true)
	{
		if(!next())
			break;
		
		XMLElement *prop = doc.NewElement("property");
		prop->SetAttribute("name", getName().c_str());

		XMLText *text = doc.NewText("");

		if(isString())
		{
			prop->SetAttribute("type", "string");

			text->SetValue(getString().c_str());
		}
		else if(isInt())
		{
			prop->SetAttribute("type", "int");

			stringstream ss;
			ss << getInt();
			text->SetValue(ss.str().c_str());
		}
		else if(isDouble())
		{
			prop->SetAttribute("type", "double");

			stringstream ss;
			ss << getDouble();
			text->SetValue(ss.str().c_str());
		}
		else if(isBool())
		{
			prop->SetAttribute("type", "bool");

			if(getBool())
				text->SetValue("1");
			else
				text->SetValue("0");
		}

		prop->InsertEndChild(text);
		root->InsertEndChild(prop);
	}

	// Save to file
	if(doc.SaveFile(filename.c_str()) != XML_NO_ERROR)
	{
		m_last_error = doc.GetErrorStr1();
		return true;
	}

	resetDirty();

	return false;
}
开发者ID:svenhertle,项目名称:fractalimages,代码行数:77,代码来源:FractalConfiguration.cpp

示例10: open

bool FractalConfiguration::open(string filename)
{
	if(invalidID())
		return true;

	m_dirty = false;

	XMLDocument doc;

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

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

	// Get data
	XMLElement *root = doc.RootElement();

	string name = string(root->Name());

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

	if(root->Attribute("id", m_id.c_str()))
	{
		XMLNode *node = root->FirstChild();

		// Loop over all properties
		while(node != NULL)
		{
			XMLElement *element = node->ToElement();

			if(element == NULL)
			{
				m_last_error = "Configuration file is invalid!";
				return true;
			}

			// Get name and type (attributes)
			const char* tmp_name = element->Attribute("name");
			const char* tmp_type = element->Attribute("type");

			if(tmp_name == NULL || tmp_type == NULL)
			{
				m_last_error = "Configuration file is invalid!";
				return true;
			}

			string name(tmp_name);
			string type(tmp_type);

			// Get text
			const char* tmp_text = element->GetText();
			string text = "";

			if(tmp_text != NULL)
				text = tmp_text;

			// Set property
			if(type == "string")
			{
				if(setStringProperty(name, text))
					return true;
			}
			else if(type == "int")
			{
				int value;
				if(stringToInt(text, &value))
				{
					m_last_error = "Error in configuration: " + text + " should be an integer";
					return true;
				}

				if(setIntProperty(name, value))
					return true;
			}
			else if(type == "double")
			{
				double value;
				if(stringToDouble(text, &value))
				{
					m_last_error = "Error in configuration: " + text + " should be a double";
					return true;
				}

				if(setDoubleProperty(name, value))
					return true;
			}
			else if(type == "bool")
			{
				bool value;
				if(text == "1")
					value = true;
				else if(text == "0")
//.........这里部分代码省略.........
开发者ID:svenhertle,项目名称:fractalimages,代码行数:101,代码来源:FractalConfiguration.cpp

示例11: LoadTilemap

bool TilemapLoader::LoadTilemap(const string _path, Tilemap& _tilemap)
{
	map_path = _path;
	// Temporary map object
	Tilemap temp_map;

	// Load TMX file in TinyXML
	XMLDocument doc;
	string temp = map_path + "/map.tmx";
	doc.LoadFile(temp.c_str());

	// Check for error in parsing
	if (doc.Error())
	{
		cout << "XML Parsing Error: " << doc.ErrorID() << endl;
		cout << "\tXML Desc: " << doc.GetErrorStr1() << endl;
		return false;
	}

	// Find the map element
	const XMLElement* map_element = doc.FirstChildElement("map");
	if (!CheckPointer(map_element, "Couldn't locate map element in map file"))
		return false;

	// Load all of the basic map data
	map_element->QueryFloatAttribute("version", &temp_map.version);
	map_element->QueryIntAttribute("width", &temp_map.map_dimensions.x);
	map_element->QueryIntAttribute("height", &temp_map.map_dimensions.y);
	map_element->QueryIntAttribute("tilewidth", &temp_map.tile_dimensions.x);
	map_element->QueryIntAttribute("tileheight", &temp_map.tile_dimensions.y);

	// Load the orientation of the tile map. Only orthogonal
	// is supported currently.
	string orient_str = map_element->Attribute("orientation");
	if (orient_str == "orthogonal")
		temp_map.orientation = SFTILE_ORIENT_ORTHOGONAL;
	else
	{
		cout << "SfTileEngine currently only supports orthogonal tile maps." << endl;
		temp_map.orientation = SFTILE_ORIENT_UNSUPPORTED;
		return false;
	}

	// Parse the tilesets in the tile map.
	const XMLElement* tileset_element = map_element->FirstChildElement("tileset");
	while (tileset_element)
	{
		if (!ParseTileset(tileset_element, temp_map.tileset))
		{
			cout << "Failed to parse tileset" << endl;
			return false;
		}
		tileset_element = tileset_element->NextSiblingElement("tileset");
	}
	// Don't let your pointer dangle... That's gross.
	tileset_element = nullptr;

	// Parse all layers: tile, object, image
	const XMLElement* layer_element = map_element->FirstChildElement();
	while (layer_element)
	{
		string name = layer_element->Name();
		if (name == "layer")
		{
			TileLayer temp_tile_layer;
			if (!ParseTileLayer(layer_element, temp_tile_layer))
			{
				cout << "Failed to parse tile layer" << endl;
				return false;
			}
			else
				temp_map.layers.push_back(unique_ptr<TileLayer>(new TileLayer(temp_tile_layer)));
		}
		else if (name == "objectgroup")
		{
			ObjectLayer temp_object_layer;
			if (!ParseObjectLayer(layer_element, temp_object_layer))
			{
				cout << "Failed to parse object layer" << endl;
				return false;
			}
			else
				temp_map.layers.push_back(unique_ptr<ObjectLayer>(new ObjectLayer(temp_object_layer)));
		}
		/*else if (layer_element->Name() == "imagelayer")
		{
			ImageLayer temp_image_layer;
			if (!ParseImageLayer(layer_element, temp_image_layer))
			{
				cout << "Failed to parse image layer" << endl;
				return false;
			}
			else
				temp_map.layers.push_back(unique_ptr<ImageLayer>(new ImageLayer(temp_image_layer)));
		}*/
		layer_element = layer_element->NextSiblingElement();
	}
	layer_element = nullptr;


//.........这里部分代码省略.........
开发者ID:Tresky,项目名称:rts,代码行数:101,代码来源:tilemap_loader.cpp


注:本文中的XMLDocument::GetErrorStr1方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。