XML parsing design using xmlpp and C++
- by shagv
I would like to use an xml format similar to the following:
<CONFIG>
<PROFILE NAME="foobar">
<PARAM ID="0" NAME="Foo" CLASS="BaseParam"/>
<PARAM ID="2" NAME="Bar" CLASS="StrIntParam">
<VALUE TYPE="STRING">some String</VALUE>
<VALUE TYPE="INT">1234</VALUE>
</PARAM>
</PROFILE>
</CONFIG>
CONFIG contains a list of PROFILEs which contain a list of PARAMs which themselves can be any structure (to be defined in the future). The idea was to define classes that parsed each PARAM type and to keep track of which class to use in the PARAM's CLASS attribute.
In code I have a config class that manages the list of profiles and a profile class that manages the list of params. I would like the profile class to handle additional param types (that inherit BaseParam) without modification to the profile class (or at the very least with minimal modification).
First of all, is this design viable? If so, what are some ways I could use different param classes and have their creation at run-time be automatic (the profile class sees the CLASS attribute and knows which type to create)?