Index: orxonox/branches/levelloader/src/levelfactory.cc
===================================================================
--- orxonox/branches/levelloader/src/levelfactory.cc	(revision 3482)
+++ orxonox/branches/levelloader/src/levelfactory.cc	(revision 3496)
@@ -19,5 +19,4 @@
 #include "levelfactory.h"
 
-
 using namespace std;
 
@@ -47,14 +46,93 @@
 	if( !XMLDoc.LoadFile())
 	{
-		// report an error somehow
-		printf("Error loading XML File: %s @ %d:%d\n", XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
-		delete( XMLDoc);
+		// report an error
+		PRINTF(ERR)("Error loading XML File: %s @ %d:%d\n", XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
+		delete XMLDoc;
 		return -1;
 	}
 	
 	// get orxonox simpleton
+	Orxonox* orx = Orxonox::getInstance();
+
 	// find the world
+	World world = orx->getWorld;
+	
+	// check basic validity
+	TiXMLElement* element = XMLDoc.RootElement();
+	TiXMLNode* comment = element->FirstChild( COMMENT);
+	
+	if( comment == NULL || ( !strcmp( comment->Value(), "OrxoLev")))
+	{
+		// report an error
+		PRINTF(ERR)("Specified XML File is not an orxonox data file (OrxoLev comment missing)\n");
+		delete XMLDoc;
+		return -1;
+	}
+	
 	// start loading objects into world
+	loadFromXMLElement( element), world, NULL);
+	
 	// free the XML data
+	delete XMLDoc;
+}
+
+/**
+   \brief recursive XML document parsing and loading function
+   \param root the XML Element to be parsed
+   \param world the world where the loaded objects shall be spawned
+   \param parent the object that is parent to all objects in current element
+*/
+
+void loadFromXMLElement( TiXMLElement* root, World* world, BaseObject* parent)
+{
+	TiXMLElement *child, *sibling;
+	BaseObject* object;
+	LoadParameters* data;
+	void* data;
+
+	if( root == NULL)
+	{
+		PRINTF(ERR)("LevelFactory tried to load from a NULL element\n");
+		return;
+	}
+
+	// load root first
+		
+		// check for LevelFactory integrity
+	if( first == NULL)
+	{
+		PRINTF(ERR)("LevelFactory does not know any ObjectFactories, loading not possible\n");
+		return;
+	}
+	
+		// gather & compile attributes
+	data = new LoadParameters( root);
+	
+		// load the object
+	object = first->load( root->Value(), data);
+	
+		// get rid of parameters
+	delete data;
+	
+	if( object != NULL)
+	{
+		// set parent
+	
+		// spawn object
+		world->spawn( object);
+		PRINTF(INFO)("Successfully loaded a '%s'\n", root->value());
+	}
+	else
+	{
+		PRINTF(ERR)("No ObjectFactory found to load '%s'\n", root->value())
+	}
+	
+	// walk children
+	child = root->FirstChildElement();
+	if( child != NULL) loadFromXMLElement( child, world, object);
+	
+	// siblings third
+	sibling = root->NextSiblingElement();
+	if( sibling != NULL) loadFromXMLElement( sibling, world, parent);
 }
 
@@ -87,4 +165,6 @@
 void LevelFactory::registerFactory( ObjectFactory* factory)
 {
+		// just to see whether it works
+	PRINTF(INFO)("'%s' registered to LevelFactory\n", factory->getClassname());
 	if( first == NULL) first = factory;
 	else first->registerFactory( factory);
@@ -153,2 +233,22 @@
 	fct.registerFactory( this);
 }
+
+/*  --------------------------------------------------
+*			LoadParameters
+*   --------------------------------------------------
+*/
+	
+const char* LoadParameters::grabParameter( const char* name)
+{
+	return root->Attribute( name);
+}
+
+const char* LoadParameters::grabParameter( const char* name, int* i)
+{
+	return root->Attribute( name, i);
+}
+
+const char* LoadParameters::grabParameter( const char* name, double* d)
+{
+	return root->Attribute( name, d);
+}
Index: orxonox/branches/levelloader/src/levelfactory.h
===================================================================
--- orxonox/branches/levelloader/src/levelfactory.h	(revision 3482)
+++ orxonox/branches/levelloader/src/levelfactory.h	(revision 3496)
@@ -11,11 +11,15 @@
 #include "xmlparser/tinystr.h"
 #include "base_object.h"
+#include "orxonox.h"
+#include "world.h"
+
+class LoadParameters;
 
 #define FACTORY_ADD(CLASS) class CLASSFactory : public ObjectFactory { \
  public:	\
-  CLASSFactory (){setNext( NULL); setClassname = "CLASS"; initialize()}; \
+  CLASSFactory (){setNext( NULL); setClassname = "CLASS"; initialize();} \
   ~CLASSFactory (); \
  private: \
-	BaseObject* fabricateObject( void* data) { return new CLASS( data)}; \
+	BaseObject* fabricateObject( LoadParameters* data) { return new CLASS( data);} \
 }; \
 CLASSFactory global_CLASSFactory();
@@ -31,12 +35,13 @@
   ~ObjectFactory ();
 
-	BaseObject* load( char* name, void* data);
+	BaseObject* load( char* name, LoadParameters* data);
 	void initialize();
   void registerFactory( ObjectFactory* factory);
 	void setClassname(char* name) {classname = name};
+	char* getClassname() {return classname};
 	void setNext( ObjectFactory* factory);
 	
  private:
-	virtual BaseObject* fabricateObject( void* data);
+	virtual BaseObject* fabricateObject( LoadParameters* data);
 	char* classname;
 	
@@ -68,3 +73,28 @@
 };
 
+//! The LoadParameters class is designed for encapsulated interfacing between TiXML and a loading costructor
+/**
+   This is the liaison between the ObjectFactories and their Objects. A LoadParameters object is passed to
+   the constructors of the objects when the ObjectFactory creates it. It can be easily parsed and features
+   special variable handling methods to extract numeric data from strings.
+*/
+class LoadParameters {
+	
+	public:
+		LoadParameters() {root = NULL;}
+		LoadParameters(TiXMLElement* element) {root = element;}
+		~LoadParameters() {}
+		
+		const char* grabParameter( const char* name);
+		const char* grabParameter( const char* name, int* i);
+		const char* grabParameter( const char* name, double* d);
+		
+		void setElement(TiXMLElement* element) {root = element;}
+		TiXMLElement* getElement() {return root;}
+		
+	private:
+		TiXMLElement* root;
+	
+};
+
 #endif /* _LEVELFACTORY_H */
