本文整理汇总了C++中TiXmlAttribute::NameTStr方法的典型用法代码示例。如果您正苦于以下问题:C++ TiXmlAttribute::NameTStr方法的具体用法?C++ TiXmlAttribute::NameTStr怎么用?C++ TiXmlAttribute::NameTStr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TiXmlAttribute
的用法示例。
在下文中一共展示了TiXmlAttribute::NameTStr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadRomGroupEntry
int MAMELoader::LoadRomGroupEntry(TiXmlElement *romgroupElmt, MAMEGameEntry *gameentry) {
MAMERomGroupEntry romgroupentry;
//First, get the "type" and "load_method" attributes. If they don't exist, we return with an error.
string load_method;
if (romgroupElmt->QueryValueAttribute("type", &romgroupentry.type) != TIXML_SUCCESS)
return 1;
if (romgroupElmt->QueryValueAttribute("load_method", &load_method) != TIXML_SUCCESS)
return 1;
// Read the encryption type string, if it exists
romgroupElmt->QueryValueAttribute("encryption", &romgroupentry.encryption);
//Iterate through the attributes of the romgroup element, recording any user-defined values.
for (TiXmlAttribute *attr = romgroupElmt->FirstAttribute(); attr; attr = attr->Next()) {
// NameTStr() is returning an std::string because we have defined TIXML_USE_STL
const string &attrName = attr->NameTStr();
// Ignore the attribute if it is "type" or "load_method"; we already dealt with those, they are mandated.
if (attrName.compare("type") && attrName.compare("load_method"))
romgroupentry.attributes[attrName] = attr->ValueStr();
}
if (load_method == "append")
romgroupentry.loadmethod = LM_APPEND;
else if (load_method == "append_swap16")
romgroupentry.loadmethod = LM_APPEND_SWAP16;
else if (load_method == "deinterlace")
romgroupentry.loadmethod = LM_DEINTERLACE;
else
return 1;
// load rom entries
for (TiXmlElement *romElmt = romgroupElmt->FirstChildElement(); romElmt != 0;
romElmt = romElmt->NextSiblingElement()) {
const string &elmtName = romElmt->ValueStr();
if (elmtName != "rom")
return 1;
romgroupentry.roms.push_back(romElmt->GetText());
}
gameentry->romgroupentries.push_back(romgroupentry);
return 0;
}
示例2: Parse
//.........这里部分代码省略.........
TIXML_STRING endTag ("</");
endTag += value;
// Check for and read attributes. Also look for an empty
// tag or an end tag.
while ( p && *p )
{
pErr = p;
p = SkipWhiteSpace( p, encoding );
if ( !p || !*p )
{
if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
return 0;
}
if ( *p == '/' )
{
++p;
// Empty tag.
if ( *p != '>' )
{
if ( document ) document->SetError( TIXML_ERROR_PARSING_EMPTY, p, data, encoding );
return 0;
}
return (p+1);
}
else if ( *p == '>' )
{
// Done with attributes (if there were any.)
// Read the value -- which can include other
// elements -- read the end tag, and return.
++p;
p = ReadValue( p, data, encoding ); // Note this is an Element method, and will set the error if one happens.
if ( !p || !*p ) {
// We were looking for the end tag, but found nothing.
// Fix for [ 1663758 ] Failure to report error on bad XML
if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
return 0;
}
// We should find the end tag now
// note that:
// </foo > and
// </foo>
// are both valid end tags.
if ( StringEqual( p, endTag.c_str(), false, encoding ) )
{
p += endTag.length();
p = SkipWhiteSpace( p, encoding );
if ( p && *p && *p == '>' ) {
++p;
return p;
}
if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
return 0;
}
else
{
if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
return 0;
}
}
else
{
// Try to read an attribute:
TiXmlAttribute* attrib = new TiXmlAttribute();
if ( !attrib )
{
return 0;
}
attrib->SetDocument( document );
pErr = p;
p = attrib->Parse( p, data, encoding );
if ( !p || !*p )
{
if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
delete attrib;
return 0;
}
// Handle the strange case of double attributes:
#ifdef TIXML_USE_STL
TiXmlAttribute* node = attributeSet.Find( attrib->NameTStr() );
#else
TiXmlAttribute* node = attributeSet.Find( attrib->Name() );
#endif
if ( node )
{
if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
delete attrib;
return 0;
}
attributeSet.Add( attrib );
}
}
return p;
}
示例3: if
//-------------------------------------------------------------------
// Method:
// Database::readXMLHelper(TiXmlNode* pParent, const unsigned int & pass)
//
// Used as a helper to recursively read in taxonomy of items from XML file.
//
// Arguments:
// "pParent" Current node in taxonomy
// "pass" the pass number: 1 is the first pass to count the number
// of generalized items in the taxonomy; 2 is to read in the
// taxonomy into memory (Tree G)
//---------------------------------------------------------------------
void
Database::readXMLHelper(TiXmlNode* pParent) {
if ( !pParent ) return;
TiXmlNode* pChild;
int t = pParent->Type();
switch (t) {
case TiXmlNode::TINYXML_ELEMENT:
if (pParent->ValueStr() == "vertex") {
TiXmlAttribute * pAttrib = pParent->ToElement()->FirstAttribute();
while (pAttrib) {
if (pAttrib->NameTStr() == "value") {
TaxVertex * newTaxVertex = new TaxVertex(atoi(pAttrib->Value()));
if (pAttrib->ValueStr() == "-1") {
G.setRoot(newTaxVertex);
headerTable[atoi(pAttrib->Value())] = newTaxVertex;
break;
}
//numGeneralizedItems++;
//cout << pAttrib->Value() << endl;
headerTable[atoi(pAttrib->Value())] = newTaxVertex;
break;
}
pAttrib=pAttrib->Next();
}
}
else if (pParent->ValueStr() == "edge") {
TiXmlAttribute * pAttrib = pParent->ToElement()->FirstAttribute();
TaxVertex * To;
TaxVertex * From;
while (pAttrib) {
if (pAttrib->NameTStr() == "to" || pAttrib->NameTStr() == "from") {
map<int, TaxVertex *>::iterator mapIt;
mapIt = headerTable.find(atoi(pAttrib->Value()));
//cout << pAttrib->ValueStr() << endl;
if (mapIt != headerTable.end()) {
if (pAttrib->NameTStr() == "to") {
To = (*mapIt).second;
}
else {
From = (*mapIt).second;
}
}
}
pAttrib=pAttrib->Next();
}
From->addChild(To);
}
break;
default:
break;
}
for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) {
readXMLHelper(pChild);
}
}