Index: code/branches/core2/bin/levels/sample.oxw
===================================================================
--- code/branches/core2/bin/levels/sample.oxw	(revision 900)
+++ code/branches/core2/bin/levels/sample.oxw	(revision 901)
@@ -1,2 +1,27 @@
+<Namespace name="test" />
+<Namespace name="blub" />
+<Namespace name="rofl" />
+
+<Namespace name="ns1">
+  <Namespace name="ns11">
+    <Namespace name="ns111">
+    </Namespace>
+    <Namespace name="ns112">
+    </Namespace>
+  </Namespace>
+  <Namespace name="ns12">
+    <Namespace name="ns121">
+    </Namespace>
+    <Namespace name="ns122">
+    </Namespace>
+  </Namespace>
+</Namespace>
+
+<Namespace name="ns1::ns12::ns121">
+  <Namespace name="ns1211">
+  </Namespace>
+</Namespace>
+<Namespace name="ns1::ns12::ns122::ns1221" />
+
 <!--
  <audio>
@@ -23,14 +48,16 @@
 <NPC position="100,0,400" scale="1" mesh="razor.mesh"/>
 
-<Model name="starship" position="200,0,500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
-<Model name="drone" position="-200,0,500" scale="10" mesh="drone.mesh" yawpitchroll="-90,-90,0">
-  <attached>
-    <Model name="drone2" position="200,-100,-500" scale="10" mesh="drone.mesh" yawpitchroll="-90,-90,0">
-      <attached>
-        <Model name="starship2" position="500,200,-500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
-      </attached>
-    </Model>
-  </attached>
-</Model>
+<Namespace name="starshipanddrone">
+  <Model name="starship" position="200,0,500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
+  <Model name="drone" position="-200,0,500" scale="10" mesh="drone.mesh" yawpitchroll="-90,-90,0">
+    <attached>
+      <Model name="drone2" position="200,-100,-500" scale="10" mesh="drone.mesh" yawpitchroll="-90,-90,0">
+        <attached>
+          <Model name="starship2" position="500,200,-500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
+        </attached>
+      </Model>
+    </attached>
+  </Model>
+</Namespace>
 
 <Model position="-200,1000,500" scale="10" mesh="hoover_body.mesh" yawpitchroll="-90,-90,0" />
@@ -40,4 +67,52 @@
 <Model position="-200,1000,500" scale="10" mesh="hoover_turbine.mesh" yawpitchroll="-90,-90,0" />
 
+<Namespace name="test" />
+<Namespace name="blub">
+</Namespace>
+<Namespace name="rofl">
+  <Namespace name="lol">
+  </Namespace>
+</Namespace>
+
+<Namespace name="ns1">
+  <Namespace name="ns11">
+    <Namespace name="ns111">
+      <Namespace name="ns1111">
+      </Namespace>
+    </Namespace>
+  </Namespace>
+  <Namespace name="ns13">
+  </Namespace>
+</Namespace>
+
+<Namespace name="ns1 ns2">
+  <Namespace name="abc" />
+</Namespace>
+
+<Namespace name="ns1::ns11 ns1::ns12 ns1::ns12::ns121">
+  <Namespace name="muhahaha" />
+</Namespace>
+
+<Namespace name="test">
+  <Namespace name="test" />
+</Namespace>
+
+<Namespace name="ns1::ns13">
+  <Namespace name="..::ns14" />
+  <Namespace name="..::..::ns3" />
+</Namespace>
+
+<Namespace name="AAA::BBB::..::CCC::..::DDD::..::BBB::BBBBBB::..::BBBBBBBBBBBBBBBBBBB::..::..::EEE" />
+
+<Namespace name="..::justatest" />
+
+<Namespace name="@file.oxw::anothertest" />
+
+<Namespace name="justonemoretest::@file.oxw::gagagaga" />
+
+<Namespace name="AAA::BBB, AAA::CCC; AAA::DDD,AAA::EEE">
+  <Namespace name="hax" />
+</Namespace>
+
     <Model position="-16779,42,11043" scale="95" mesh="ast2.mesh" rotationAxis="0.281711,0.152518,0" rotationRate="27" />
     <Model position="12893,-1583,-17939" scale="48" mesh="ast1.mesh" rotationAxis="0.0597998,0.923364,0" rotationRate="36" />
@@ -45,5 +120,5 @@
     <Model position="-9583,-2284,-19904" scale="33" mesh="ast5.mesh" rotationAxis="0,0.675659,0.0196445" rotationRate="44" />
     <Model position="-19597,-15494,3163" scale="37" mesh="ast5.mesh" rotationAxis="0.477996,0,0.048639" rotationRate="23" />
-    <Model position="-182,6442,-4496" scale="25" mesh="ast5.mesh" rotationAxis="0.142225,0,0.154393" rotationRate="37" />
+    <!--Model position="-182,6442,-4496" scale="25" mesh="ast5.mesh" rotationAxis="0.142225,0,0.154393" rotationRate="37" />
     <Model position="1004,-19639,-13744" scale="21" mesh="ast1.mesh" rotationAxis="0.974865,0.299775,0" rotationRate="29" />
     <Model position="-13204,-10191,-1555" scale="31" mesh="ast1.mesh" rotationAxis="0.41675,0,0.385001" rotationRate="42" />
@@ -266,3 +341,3 @@
     <Model position="1991,-11949,-15733" scale="68" mesh="ast1.mesh" rotationAxis="0,0.390655,0.623811" rotationRate="41" />
     <Model position="-6787,1792,287" scale="71" mesh="ast6.mesh" rotationAxis="0.161019,0.130015,0" rotationRate="36" />
-    <Model position="-7223,-13574,-11873" scale="24" mesh="ast4.mesh" rotationAxis="0.792203,0,0.177188" rotationRate="38" />
+    <Model position="-7223,-13574,-11873" scale="24" mesh="ast4.mesh" rotationAxis="0.792203,0,0.177188" rotationRate="38" /-->
Index: code/branches/core2/src/orxonox/core/Loader.cc
===================================================================
--- code/branches/core2/src/orxonox/core/Loader.cc	(revision 900)
+++ code/branches/core2/src/orxonox/core/Loader.cc	(revision 901)
@@ -115,6 +115,8 @@
             ticpp::Document xmlfile(level->getFile());
             xmlfile.LoadFile();
+
             ticpp::Element rootElement;
             rootElement.SetAttribute("name", "root");
+            rootElement.SetAttribute("bAutogenerated", true);
 
             for (ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++)
@@ -126,8 +128,10 @@
             rootNamespace->setLevel(level);
             rootNamespace->setNamespace(rootNamespace);
-            rootNamespace->deleteNamespaceNodesAfterDestruction(true);
+            rootNamespace->setRoot(true);
             rootNamespace->XMLPort(rootElement, true);
 
             COUT(0) << "Finished loading " << level->getFile() << "." << std::endl;
+
+            COUT(4) << "Namespace-tree:" << std::endl << rootNamespace->toString("  ") << std::endl;
 
             return true;
Index: code/branches/core2/src/orxonox/core/Namespace.cc
===================================================================
--- code/branches/core2/src/orxonox/core/Namespace.cc	(revision 900)
+++ code/branches/core2/src/orxonox/core/Namespace.cc	(revision 901)
@@ -41,5 +41,5 @@
 
         this->bAutogeneratedFileRootNamespace_ = false;
-        this->bDeleteNamespaceNodesAfterDestruction_ = false;
+        this->bRoot_ = false;
         this->operator_ = "or";
     }
@@ -47,5 +47,5 @@
     Namespace::~Namespace()
     {
-        if (this->bDeleteNamespaceNodesAfterDestruction_)
+        if (this->bRoot_)
             for (std::set<NamespaceNode*>::iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); ++it)
                 delete (*it);
@@ -73,10 +73,17 @@
             name.replace(pos, 1, " ");
         SubString tokens(name, " ", "", false, '\\', '"', '\0', '\0', '\0');
-        for (unsigned int i = 0; i < tokens.size(); i++)
+        if (this->bRoot_)
         {
-            for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it)
+            this->representingNamespaces_.insert(new NamespaceNode(this->getName()));
+        }
+        else
+        {
+            for (unsigned int i = 0; i < tokens.size(); i++)
             {
-                std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]);
-                this->representingNamespaces_.insert(temp.begin(), temp.end());
+                for (std::set<NamespaceNode*>::iterator it = this->getNamespace()->representingNamespaces_.begin(); it != this->getNamespace()->representingNamespaces_.end(); ++it)
+                {
+                    std::set<NamespaceNode*> temp = (*it)->getNodeRelative(tokens[i]);
+                    this->representingNamespaces_.insert(temp.begin(), temp.end());
+                }
             }
         }
@@ -138,3 +145,35 @@
         return false;
     }
+
+    std::string Namespace::toString() const
+    {
+        std::string output;
+
+        int i = 0;
+        for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it)
+        {
+            if (i > 0)
+                output += " / ";
+
+            output += (*it)->toString();
+        }
+
+        return output;
+    }
+
+    std::string Namespace::toString(const std::string& indentation) const
+    {
+        std::string output;
+
+        int i = 0;
+        for (std::set<NamespaceNode*>::const_iterator it = this->representingNamespaces_.begin(); it != this->representingNamespaces_.end(); i++, ++it)
+        {
+            if (i > 0)
+                output += "\n";
+
+            output += (*it)->toString(indentation);
+        }
+
+        return output;
+    }
 }
Index: code/branches/core2/src/orxonox/core/Namespace.h
===================================================================
--- code/branches/core2/src/orxonox/core/Namespace.h	(revision 900)
+++ code/branches/core2/src/orxonox/core/Namespace.h	(revision 901)
@@ -59,14 +59,17 @@
                 { return this->operator_; }
 
+            void setRoot(bool bRoot)
+                { this->bRoot_ = bRoot; }
+
             bool includes(const Namespace* ns) const;
             bool isIncludedIn(const Namespace* ns) const { return ns->includes(this); }
 
-            void deleteNamespaceNodesAfterDestruction(bool bDelete)
-                { this->bDeleteNamespaceNodesAfterDestruction_ = bDelete; }
+            std::string toString() const;
+            std::string toString(const std::string& indentation) const;
 
         private:
             std::set<NamespaceNode*> representingNamespaces_;
             bool bAutogeneratedFileRootNamespace_;
-            bool bDeleteNamespaceNodesAfterDestruction_;
+            bool bRoot_;
             std::string operator_;
     };
Index: code/branches/core2/src/orxonox/core/NamespaceNode.cc
===================================================================
--- code/branches/core2/src/orxonox/core/NamespaceNode.cc	(revision 900)
+++ code/branches/core2/src/orxonox/core/NamespaceNode.cc	(revision 901)
@@ -49,5 +49,5 @@
         std::set<NamespaceNode*> nodes;
 
-        if (name == "")
+        if ((name.size() == 0) || (name == ""))
         {
             nodes.insert(this);
@@ -56,6 +56,12 @@
         {
             unsigned int pos = name.find("::");
-            std::string firstPart = name.substr(0, pos);
-            std::string secondPart = name.substr(pos + 2, std::string::npos);
+            std::string firstPart = name;
+            std::string secondPart;
+
+            if (pos != std::string::npos)
+            {
+                firstPart = name.substr(0, pos);
+                secondPart = name.substr(pos + 2, std::string::npos);
+            }
 
             if (firstPart == "..")
@@ -64,4 +70,9 @@
                 {
                     COUT(2) << "Warning: Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", namespace is root." << std::endl;
+                    nodes = this->getNodeRelative(secondPart);
+                }
+                else if (!this->parent_)
+                {
+                    COUT(2) << "Warning: Can't go to enclosing namespace with '..' operator in namespace " << this->name_ << ", no parent namespace set." << std::endl;
                     nodes = this->getNodeRelative(secondPart);
                 }
@@ -78,10 +89,17 @@
 
                 if ((*it).second->isHidden())
+                {
                     COUT(2) << "Warning: Subnamespace '" << firstPart << "' in namespace '" << this->name_ << "' is hidden and can't be accessed." << std::endl;
+                    nodes.insert(this);
+                }
                 else
+                {
                     nodes = (*it).second->getNodeRelative(secondPart);
+                }
             }
             else
             {
+                bool bFoundMatchingNamespace = false;
+
                 for (std::map<std::string, NamespaceNode*>::iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
                 {
@@ -90,5 +108,12 @@
                         std::set<NamespaceNode*> temp2 = (*it).second->getNodeRelative(secondPart);
                         nodes.insert(temp2.begin(), temp2.end());
+                        bFoundMatchingNamespace = true;
                     }
+                }
+
+                if (!bFoundMatchingNamespace)
+                {
+                    COUT(2) << "Warning: No file included with name '" << firstPart.substr(1, std::string::npos) << "' at this part of the level file, using parent namespace instead." << std::endl;
+                    nodes = this->getNodeRelative(secondPart);
                 }
             }
@@ -113,3 +138,36 @@
         return false;
     }
+
+    std::string NamespaceNode::toString() const
+    {
+        std::string output = this->name_;
+
+        if (this->subnodes_.size() > 0)
+        {
+            output += " (";
+
+            int i = 0;
+            for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); i++, ++it)
+            {
+                if (i > 0)
+                    output += ", ";
+
+                output += (*it).second->toString();
+            }
+
+            output += ")";
+        }
+
+        return output;
+    }
+
+    std::string NamespaceNode::toString(const std::string& indentation) const
+    {
+        std::string output = (indentation + this->name_ + "\n");
+
+        for (std::map<std::string, NamespaceNode*>::const_iterator it = this->subnodes_.begin(); it != this->subnodes_.end(); ++it)
+            output += (*it).second->toString(indentation + "  ");
+
+        return output;
+    }
 }
Index: code/branches/core2/src/orxonox/core/NamespaceNode.h
===================================================================
--- code/branches/core2/src/orxonox/core/NamespaceNode.h	(revision 900)
+++ code/branches/core2/src/orxonox/core/NamespaceNode.h	(revision 901)
@@ -53,4 +53,7 @@
             bool includes(const NamespaceNode*) const;
 
+            std::string toString() const;
+            std::string toString(const std::string& indentation) const;
+
         private:
             std::string name_;
Index: code/branches/core2/src/orxonox/core/XMLPort.h
===================================================================
--- code/branches/core2/src/orxonox/core/XMLPort.h	(revision 900)
+++ code/branches/core2/src/orxonox/core/XMLPort.h	(revision 901)
@@ -256,6 +256,12 @@
                                             newObject->setNamespace(object->getNamespace());
                                             if (this->bLoadBefore_)
+                                            {
                                                 newObject->XMLPort(*child, true);
-                                            COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl;
+                                                COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl;
+                                            }
+                                            else
+                                            {
+                                                COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (object not yet loaded) to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl;
+                                            }
                                             (*object.*this->loadfunction_)(newObject);
                                             if (!this->bLoadBefore_)
