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

PIN*_*INK 4 c++ xml tinyxml2

嗨,有人知道如何使用tinyxml2在字符串变量中查询属性吗?

例:

<pattern>
    <distances numberOfDistances="1" realWorldPixelSize="0.26428571428571429">
        <markerDistance linkName="AB" distance="58.624385902531891"/>
    </distances>
</pattern>
Run Code Online (Sandbox Code Playgroud)

为了获取distance属性,我使用

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

我以为字符串是这样的:

std::string linkName;
child->QueryAttribute("linkName", &linkName);
Run Code Online (Sandbox Code Playgroud)

但是对于字符串,似乎没有重载。

PIN*_*INK 6

好的,我找到了。

使用:

const char * name
name = child->Attribute("linkName");
Run Code Online (Sandbox Code Playgroud)