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


C++ XmlDocument::getRootElement方法代码示例

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


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

示例1: Exception

void
MyScene1::loadSceneFile(const char *filePath)
{
	// load XML scene file
	XmlDocument doc;
	doc.fromFile(File::getPath(filePath));

	// make sure the root element is named correctly
	const XmlElement *root = doc.getRootElement();
	if(root->getName() != "dromescene")
		throw Exception("MyScene1::loadSceneFile(): Invalid root element name");

	vector < RefPtr <Texture> > textures;

	// loop through each child element
	for(unsigned int i = 0; i < root->getNumChildren(); ++i) {
		const XmlElement *child = root->getChild(i);

		if(child->getName() == "texture") {
			// create texture
			const XmlAttribute *attr = child->getAttribute("filePath");
			if(!attr)
				throw Exception("MyScene1::loadSceneFile(): Texture without filePath");
			textures.push_back(Texture::create(Image::create(attr->getValue())));
		} else if(child->getName() == "block") {
			// parse position
			const XmlAttribute *attr = child->getAttribute("position");
			if(!attr)
				throw Exception("MyScene1::loadSceneFile(): Block without position");
			Vector3 position(attr->getValue());

			// parse bounds
			attr = child->getAttribute("bounds");
			if(!attr)
				throw Exception("MyScene1::loadSceneFile(): Block without bounds");
			Vector3 bounds(attr->getValue());

			// parse texture index
			attr = child->getAttribute("textureIndex");
			unsigned int index = (attr != NULL) ? (unsigned int)String(attr->getValue()).toInt() : 0;
			if(index >= textures.size())
				throw Exception("MyScene1::loadSceneFile(): Block with invalid texture index");

			// parse normalmap index
			RefPtr <Texture> normalmap;
			attr = child->getAttribute("normalmapIndex");
			if(attr != NULL) {
				unsigned int tmp = (unsigned int)String(attr->getValue()).toInt();
				if(tmp >= textures.size())
					throw Exception("MyScene1::loadSceneFile(): Block with invalid normalmap index");
				normalmap = textures[tmp];
			}

			// create block
			m_sceneObjects.push_back(new Block(position, bounds, textures[index], normalmap));
		} else {
			throw Exception("MyScene1::loadSceneFile(): Invalid element name '" + child->getName() + "'");
		}
	}
}
开发者ID:Melstolit,项目名称:DromeEngine,代码行数:60,代码来源:MyScene1.cpp


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