本文整理汇总了C++中xml::Node::childNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ Node::childNodes方法的具体用法?C++ Node::childNodes怎么用?C++ Node::childNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml::Node
的用法示例。
在下文中一共展示了Node::childNodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
GameMap::UniquePtr TiledMapParser::parse()
{
using namespace Poco;
loadMapImages(fileInfo);
ifstream in(Constants::MapPath + fileInfo.getTmxFileName());
if (!in.good())
{
throw FileLoadException("Unable to load the Tiled tmx file: " + Constants::MapPath + fileInfo.getTmxFileName());
}
XML::InputSource src(in);
XML::DOMParser parser;
AutoPtr<XML::Document> doc = parser.parse(&src);
MapProperties properties;
std::map<uint, terrainFactory> terrainFactories;
GameMap::NavGraphList navGraph;
XML::NodeIterator iterator(doc, XML::NodeFilter::SHOW_ELEMENT);
XML::Node* node = iterator.nextNode();
while (node)
{
if (node->nodeName() == "map")
{
if (!node->hasAttributes()) throw FileFormatException("The Tiled map file is formatted incorrectly: there are no map attributes.");
// Load the properties.
properties = processMapProperties(node);
ScopedNodeList childNodes = node->childNodes();
for (int i = 0; i < childNodes->length(); ++i)
{
auto childNode = childNodes->item(i);
if (childNode->nodeName() == "tileset")
{
terrainFactories = setFactories(childNode);
}
else if (childNode->nodeName() == "layer")
{
processTerrain(navGraph, terrainFactories, childNode, properties);
}
}
}
else
{
// Postconditions:
Assert<FileFormatException>(properties.rows != 0, "Properties not loaded from Tiled map file.");
Assert<FileFormatException>(!navGraph.empty(), "NavGraph not loaded from Tiled map file.");
// Everything has been processed, so no need to continue iteration.
break;
}
node = iterator.nextNode();
}
GameMap::UniquePtr gameMap = make_unique<GameMap>(properties.rows, properties.columns,
properties.tileHeight, properties.tileWidth, move(navGraph));
return move(gameMap);
}