= HowTo: XML Loading = [[TracNav(TracNav/TOC_Development)]] To make a new class XML-loadable, you have to do three things: == 1. Derive from !BaseObject == First the new class has to derive directly or indirectly from [wiki:BaseObject] (indirectly: deriving from another class following the same rule): MyClass.h file: {{{ #include "core/BaseObject.h" class MyClass : public BaseObject { public: MyClass(); virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); ... }; or #include "OtherClass.h" class MyClass : public OtherClass // If OtherClass is a BaseObject too { ... }; }}} == 2. Create a Factory == Additionally you have to create a [wiki:Factory] for the new class. Use the [wiki:CoreIncludes CreateFactory] macro outside a function in a source file: MyClass.cc file: {{{ #include "MyClass.h" CreateFactory(MyClass); // Constructor: MyClass::MyClass() { RegisterObject(MyClass); } ... }}} == 3. XMLPort == At last you have to implement the [wiki:XMLPort] function for the new clss: {{{ void MyClass::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(MyClass, XMLPort, xmlelement, mode); XMLPortParam(SomeClass, ...); XMLPortParam(SomeClass, ...); XMLPortParam(SomeClass, ...); ... XMLPortObject(SomeClass, ...); ... } }}} Read the related page to learn more about XMLPort and how to load parameters and subobjects: * [wiki:XMLPort]