2015-11-27 27 views
2

嗨確實有人知道如何查詢字符串變量的屬性,使用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); 

但是,對於一個字串似乎沒有超載。

回答

3

好的,我找到了。

用途:

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