Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To query a string attribute with tinyxml2?

Tags:

c++

xml

tinyxml2

Hi does someone know how to to query a attribute in to a string variable, using tinyxml2?

Example:

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

To get the distance attribute I use

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

I thought for a string it would be something like this:

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

But for a string there seems to be no overload.

like image 218
TruckerCat Avatar asked Nov 27 '15 16:11

TruckerCat


1 Answers

Ok, I found it.

Use:

const char * name
name = child->Attribute("linkName");
like image 148
TruckerCat Avatar answered Oct 15 '22 06:10

TruckerCat