【发布时间】:2012-04-12 01:15:33
【问题描述】:
我正在尝试找出一种方法来从我使用 TinyXML2 创建的 XML 文档中加载文本。这是整个文档。
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="15" height="13" tilewidth="32" tileheight="32">
<tileset firstgid="1" name="Background" tilewidth="32" tileheight="32">
<image source="background.png" width="64" height="32"/>
</tileset>
<tileset firstgid="3" name="Block" tilewidth="32" tileheight="32">
<image source="block.png" width="32" height="32"/>
</tileset>
<layer name="Background" width="15" height="13">
<data encoding="base64">
AgAAAAIAAAACAAAA...
</data>
</layer>
<layer name="Block" width="15" height="13">
<data encoding="base64">
AwAAAAMAAAADAAAAAwAAAAM...
</data>
</layer>
</map>
基本上,我只想将<data> 中的文本复制到一个名为background 的字符串中,前提是图层名称为"Background"。
我得到了像这样的其他变量:
// Get the basic information about the level
version = doc.FirstChildElement("map")->FloatAttribute("version");
orientation = doc.FirstChildElement("map")->Attribute("orientation");
mapWidth = doc.FirstChildElement("map")->IntAttribute("width");
mapHeight = doc.FirstChildElement("map")->IntAttribute("height");
这很好用,因为我知道元素名称和属性名称。有没有办法说获取doc.FirstChildElement("map")->FirstChildElement("layer"),如果是== "Background",获取文本。
我将如何做到这一点?
【问题讨论】: