Connecting Tech Pros Worldwide Forums | Help | Site Map

Object initialization and xml question

BCC
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi,

Im having some problems initializing an object with values from an xml file.
Given:
class MyObject {
public:
int m_x;
double m_y;
std::string m_s;
}

And an xml file with the following tags:
<m_x>1</m_x>
<m_y>5.9</m_y>
<m_s>Hello!</m_s>

I can parse the file okay (using msxml), but have no way to relate the
variables in the file to the variables in the object without a load of
if/then statements. Is there any way to do something like:
MyObject obj;
obj.nodename = nodevalue; // ??????

Without doing:
if (nodname == "m_x") obj.m_x = nodevalue;

I have object that have tons of variables, and in the xml file, any number
may be set or left at the defaults. So I would much rather prefer avoiding
a list of flow control statements that all have to be modified if I add or
remove a variable.

I thought about using an stl map, but with different types there seems to be
no way to go about this.

Any suggestions or ideas?

Thanks,
Bryan


Closed Thread