Jason - 2012-06-07

Hello everybody, I'm currently working on an integration of XML with a game engine and I'm stumbled upon a problem, I'm trying to expand TinyXML for the engine in which I'm creating a bunch of external functions to load the XML data. However, it seems my function to access a attributes value isn't working once I 'parse' or 'load' the file which I'm doing beforehand. My functions are below.

Function to load the XML before hand.
[code
//---------------------------------------------------
// Purpose:
//---------------------------------------------------
void ReadXMLWeaponDataFromFileForSlot( const char *szXMLWeaponName, TiXmlDocument Doc )
{
char sz;
Q_snprintf( sz, sizeof( sz ), GetFullPathToXMLFile( "weapons/%s.xml" ), szXMLWeaponName );
bool loadOkay = Doc.LoadFile( sz );

if ( loadOkay )
ConColorMsg(Color( 196, 145 ,63 , 255 ), "Loaded Weapon Script %s\n", sz );
else
ConColorMsg(Color( 196, 145 ,63 , 255 ), "Error with XML! \n", Doc.ErrorDesc() );
}

This refuses to work with how I do it at the bottom! If I do separately it will work.

const char * GetElementDoubleChildValue( TiXmlDocument docId, const char *ElementID, const char* DoubleChildID, const char* TripleChildID )
{
    TiXmlNode * iNode = docId.FirstChild( ElementID );
    if( iNode != NULL )
    {
        for( TiXmlNode * itemNode = iNode->FirstChild( DoubleChildID ); itemNode != NULL; itemNode = iNode->IterateChildren( DoubleChildID, itemNode ) )
        {
            TiXmlNode * nameNode = itemNode->FirstChild( TripleChildID );
            if( nameNode != NULL && nameNode->ToElement() != NULL )
            {
                ConColorMsg(Color( 196, 145 ,63 , 255 ), "Name is %s \n", nameNode->ToElement()->FirstAttribute()->Value() );
                return nameNode->ToElement()->FirstAttribute()->Value();
            }
        }
    }

    return 0;
}

And when I'm calling all these together, this is how it looks, ( Perhaps a suggestion on how to make this better would be appreciated! )

TiXmlDocument BLAHDOC;
ReadXMLWeaponDataFromFileForSlot( "weapon_pistol", BLAHDOC );
Msg("This is the First Person attri value: %s", GetElementDoubleChildValue( BLAHDOC, "weapondata", "geometry", "firstperson" ) );