add query string method
This commit is contained in:
11
tinyxml2.h
11
tinyxml2.h
@@ -1361,6 +1361,17 @@ public:
|
|||||||
return a->QueryFloatValue( value );
|
return a->QueryFloatValue( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// See QueryIntAttribute()
|
||||||
|
XMLError QueryStringAttribute(const char* name, const char** value) const {
|
||||||
|
const XMLAttribute* a = FindAttribute(name);
|
||||||
|
if (!a) {
|
||||||
|
return XML_NO_ATTRIBUTE;
|
||||||
|
}
|
||||||
|
*value = a->Value();
|
||||||
|
return XML_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Given an attribute name, QueryAttribute() returns
|
/** Given an attribute name, QueryAttribute() returns
|
||||||
XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion
|
XML_SUCCESS, XML_WRONG_ATTRIBUTE_TYPE if the conversion
|
||||||
|
|||||||
@@ -827,6 +827,14 @@ int main( int argc, const char ** argv )
|
|||||||
XMLTest("Attribute: unsigned", (int)XML_SUCCESS, queryResult, true);
|
XMLTest("Attribute: unsigned", (int)XML_SUCCESS, queryResult, true);
|
||||||
XMLTest("Attribute: unsigned", unsigned(100), v, true);
|
XMLTest("Attribute: unsigned", unsigned(100), v, true);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
const char* v = "failed";
|
||||||
|
int queryResult = element->QueryStringAttribute("not-attrib", &v);
|
||||||
|
XMLTest("Attribute: string default", false, queryResult == XML_SUCCESS);
|
||||||
|
queryResult = element->QueryStringAttribute("attrib", &v);
|
||||||
|
XMLTest("Attribute: string", (int)XML_SUCCESS, queryResult, true);
|
||||||
|
XMLTest("Attribute: string", "100", v);
|
||||||
|
}
|
||||||
XMLTest("Attribute: unsigned", unsigned(100), element->UnsignedAttribute("attrib"), true);
|
XMLTest("Attribute: unsigned", unsigned(100), element->UnsignedAttribute("attrib"), true);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user