C++ XML Objects Use: An XML file

Previous Next Usage Home Installation Docs

Abstract

Now we want an XML to read these from.

Description

Here is a possible XML file that we might have which defines the values for the objects, and also provides for the composite objects (including the pointer):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<root>
	<x>1</x>	
	<foos>
		<foo>
			<x>1</x>
			<y>2.1</y>
			<z/>
		</foo>
		<foo>
			<x>4</x>
			<y>10</y>
		</foo>
	</foos>
	<bars>
		<bar>
			<a>3</a>
			<b>7.6</b>
			<c>5</c>
		</bar>
		<bar>
			<a>22</a>
			<b>999.999</b>
			<c>53</c>
		</bar>
	</bars>
	<a_foo>
		<foo>
			<x>5</x>
			<y>7</y>
		</foo>
	</a_foo>
</root>

There are lot's of other features of the XML format like the ability to include pieces of XML from other files, but that will be discussed later.

You can see that objects are declared by naming the "type" of the object as the tag, and members are defined by using the name of the member as a tag, followed by the data from the member. For members which are composite (vectors and references), the data for the member is actually an object declaration.

The "types" of the objects just happen to match the name of the type in XML file in this case. A registration mechanism is used (Abstract Factory Pattern), which de couples the name of the class from the string name which represents it. So the actual class could be called "CFoo", but the name in the xml file could be "foo".

You can also see that there is very little difference between a pointer to an object and a vector of pointers, except that you can only have 1 object in the reference.

Previous Next Usage Home Installation Docs


Generated: Wed Apr 5 23:00:20 EST 2006

Copyright (c) 2005; Paul Hamilton; pHamtec P/L.

Use, modification, and distribution is provided free of any limitations.