Object initialization and xml question

From: BCC (a_at_b.c)
Date: 02/28/05


Date: Sun, 27 Feb 2005 23:51:24 GMT

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



Relevant Pages

  • Object initialization and xml question
    ... Im having some problems initializing an object with values from an xml file. ... class MyObject { ... And an xml file with the following tags: ...
    (comp.lang.cpp)
  • Re: How to initialize a C++ object from XML?
    ... BCC wrote: ... > class MyObject { ... > the objects variables or I may have all of ... > to see if it has been set in the xml file. ...
    (comp.programming)
  • How to initialize a C++ object from XML?
    ... class MyObject { ... And in an XML file I have something like this: ... </variable initialization> ... that still doesnt sound nice. ...
    (comp.programming)
  • Re: How Do I search an XML File?
    ... If the XML file is well-formed and the data structure is stable, you could read the file in using the scriptlet library filesystemobject in Access 2000; look up createfileobject for some code examples. ... Or, you can use the old dos style file open, read the file in a line at a time, look for the tags that encapsulate the content you want, pop that information into an array, then deal with the 'hits' after you have completed your line by line scan of the file. ... or is the skill a child node of the employee? ... I also need to scan for the employee skill set if it matches a certain ...
    (microsoft.public.access.externaldata)
  • Re: Reading Reults of txt file - and then...
    ... I need it to execute another file if it finds ... >>I am using FSO to read a XML file, using the ReadAll method. ... First how does an XML file appear to wsh? ... > Once you have found these tags (or not, depending on whether or not they are ...
    (microsoft.public.scripting.vbscript)