473,472 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to initialize a C++ object from XML

BCC
I have some c++ code like this:
class MyObject {
public:
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">
<a>10</a>
<b>3 </a>
<m>332</m>
</object>
<object id="2">
<a>15</a>
<b>5 </a>
<m>110</m>
</object>
</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
accordingly.

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
them.

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...

Thanks,
Bryan

Jul 20 '05 #1
0 1776

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: myang | last post by:
Hi, I am trying to construct a 'point' instance with two different methods (see the following codes). Why the second one can't work? It's strange, since 'self' refers to the newly created...
6
by: steveneng | last post by:
C++ Primer Plus Programming Exercises 4th Ed - Prate Help I'm trying to refresh myself and I'm stuck on this problem (not homework/school related but for personal advancement). 6: Do...
74
by: Peter | last post by:
Hi, So many times, I have seen compile warning: "you used a char* without initilize it", probably on the code like this: ------------ char* ptr; func(..., ptr); ----------
4
by: Mark Hannon | last post by:
I am trying to initialize an array only once so it can be seen & used by any functions that need it. As I understand it, if a variable is declared by itself outside of any functions, its scope is...
4
by: bob | last post by:
Why doesn't c++ let me initialize static members like this: class MySound { static CSoundManager* g_pSoundManager = NULL; };
22
by: silversurfer2025 | last post by:
Hello everybdy, I am a little confused for the following reason: In my code I used a simple for-loop in order to initialize a 2D-array of floats to zero. Because of efficiency reasons, I changed...
18
by: toton | last post by:
Hi, In C++ when I initialize an array it, also initializes the class that it contains, which calls the default constructor. However, I want to initialize the array only (i.e reserve the space) and...
15
by: thinktwice | last post by:
char a = { 0 } is it ok?
14
by: 2005 | last post by:
If a Constructor can be used to initialize, when is memory is allocated / say the "new" operator etc? Thanks
4
by: Bram Kuijper | last post by:
Hi all, as a C++ newbie, I got some question on the initialization of static reference data members. Since it isn't possible to initialize static members of a class in the constructor, I...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.