示例#1
0
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
0
const char* TiXmlElement::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
	p = SkipWhiteSpace( p, encoding );
	TiXmlDocument* document = GetDocument();

	if ( !p || !*p )
	{
		if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, 0, 0, encoding );
		return 0;
	}

	if ( data )
	{
		data->Stamp( p, encoding );
		location = data->Cursor();
	}

	if ( *p != '<' )
	{
		if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, p, data, encoding );
		return 0;
	}

	p = SkipWhiteSpace( p+1, encoding );

	// Read the name.
	const char* pErr = p;

    p = ReadName( p, &value, encoding );
	if ( !p || !*p )
	{
		if ( document )	document->SetError( TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, pErr, data, encoding );
		return 0;
	}

    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
0
//-------------------------------------------------------------------
// 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);
	}
}