如何使用tinyxml2查询字符串属性?

时间:2015-11-27 16:37:51

标签: c++ xml tinyxml2

您是否有人知道如何使用tinyxml2?

查询字符串变量中的属性

示例:

<pattern>
    <distances numberOfDistances="1" realWorldPixelSize="0.26428571428571429">
        <markerDistance linkName="AB" distance="58.624385902531891"/>
    </distances>
</pattern>

要获取我使用的距离属性

for (tinyxml2::XMLElement* child = distancesElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
    {
        double distance;
        child->QueryAttribute("distance", &distance);
        distances.push_back(MarkerDistance(linkName, distance));
    }

我想要一个字符串,就像这样:

std::string linkName;
child->QueryAttribute("linkName", &linkName);

但是对于一个字符串似乎没有过载。

1 个答案:

答案 0 :(得分:5)

好的,我找到了。

使用:

const char * name
name = child->Attribute("linkName");