本文整理汇总了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() + "'");
}
}
}