• Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  


Well, Deranged has pointed me to TinyXML, so I might just scrap the current file parser I'm working on. It depends on if I can use TinyXML to fill instances of class "item" with the information parsed from an XML file. Could anyone reading this comment and let me know if it's possible and a good idea to use TinyXML to parse an XML file like below (this is just a guess at what an XML file would look like, I don't have any experience with XML) into a C++ object like [also] below?

EDIT: Hah, the past three entries have started with "Well". Ironic, since I'm not feeling at all "well" right now!

"Mana Potion">
A potion of Mana



class item {
string name;
int price;
string desc;
mapint> effects;
int InvenQuant, EquipQuant, StoreQuant;

Sign in to follow this  

1 Comment

Recommended Comments

In case it's useful to you, you could try Daabli (http://sourceforge.net/projects/daabli/) for loading your C++ objects.

The code for loading your structure would look like this:
#include "Daabli.h"

class Item
std::string _name;
int _price;
std::string _desc;
std::map<std::string, int> _effects;
int _invenQuant;
int _equipQuant;
int _storeQuant;

const bool Read(Daabli::Reader &r)
r.Read( "name", _name ) && // required
r.Read( "price", _price, 0 ) && // optional
r.Read( "desc", _desc ) && // required
r.Read( "effects", _effects ) && // required
r.Read( "inventory", _invenQuant, 0 ) && // optional
r.Read( "equipment", _equipQuant, 0 ) && // optional
r.Read( "store", _storeQuant, 0 ); // optional

int main(int /*argc*/, char * /*argv*/[])
Daabli::Reader r;

if( !r.FromFile( "input.txt" ) )
return -1;

Item item;

// Read the item
if( !r.Read( "item", item ) )
return -1;

// Do something with item here

return 0;

And the input.txt data file would look like this:
item =

name = "Mana Potion";
desc = "A potion of Mana";
effects =
{ "mana", 10 },
{ "life", 1 } // gives some life also
inventory = 5;
equipment = 1;
store = 10;

For more information about Daabli, see this thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=539326

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement