C++ XML Objects Use: Generics |
Previous Next Usage Home Installation Docs
It is possible that you don't want, or need, to care about the syntax of the XML file that is read. So far, each tag that appears in the XML file needed to have an associated object registered with that name, or be a member of an object.
By overriding a different type of "xmlobj_context" called "generic_context" when you read in the file, you will get a new type of object called "generic" which will be created for any objects that appear in the file that aren't registered.
Studying the way that generic was developed can also help in working out ways in which you can non-intrusively extend C++ XML Objects to do other interesting things.
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"?>
<genroot name="root">
<x>1</x>
<a_foo>
<genfoo name="foo_3">
<x>5</x>
<y>7</y>
</genfoo>
</a_foo>
<foos>
<genfoo name="foo_1">
<x>1</x>
<y>2.1</y>
<z/>
<bars>
<genbar name="bar_3">
<x>10</x>
<y>10.5</y>
<z>22</z>
<a_foo>
<genfoo name="foo_4">
<x>5</x>
<y>7</y>
<s>A string</s>
</genfoo>
</a_foo>
</genbar>
</bars>
</genfoo>
<genfoo name="foo_2">
<x>4</x>
<y>10</y>
</genfoo>
</foos>
<bars>
<genbar name="bar_1">
<x>3</x>
<y>7.6</y>
<z>5</z>
</genbar>
<genbar name="bar_2">
<x>22</x>
<y>999.999</y>
<z>53</z>
</genbar>
</bars>
</genroot>
The big difference with this example is that we never registered the objects "genroot", "genfoo" or "genbar". If this file is read in using a derivation of "generic_context", a new object will be created without any syntax errors being generated.
You can still register your own objects with the system as well as using the generic one for objects that you don't. Just derived from generic_context rather than xmlobj_context.
To include a generic object in your hierarchy, make sure you use the more general xmlobj_ref and xmlobj_vector rather than the typed variety to hold the new objects, since they won't have internal C++ types (other than xmlobj::generic).
Previous 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.