Object initialization and xml question

B

BCC

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top