How to initialize a C++ object from XML

Discussion in 'XML' started by BCC, Feb 22, 2005.

  1. BCC

    BCC Guest

    I have some c++ code like this:
    class MyObject {
    int m_a;
    int m_b;
    int m_c;
    // etc. etc.

    And in an XML file I have something like this:
    <variable initialization>
    <object id="1">
    <b>3 </a>
    <object id="2">
    <b>5 </a>
    </variable initialization>

    Where basically I have a list of objects, and I need to create that number
    (in this case 2) of objects, and initialize their member variables

    What is a nice way to do this? In the xml file, I may only have 1 or 2 of
    the objects variables (and there can be a lot of these) or I may have all of

    It seems the obvious but painful way would be when I get my xml document
    loaded, to go through the thing and search for every variable in my object
    to see if it has been set in the xml file. I thought about a hash map, but
    that still doesnt sound nice.

    I would guess people have to do this all the time, any suggestions besides a
    load of if/then statements?

    Im using MSXML by the way...

    BCC, Feb 22, 2005
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page