Index: /XIOS3/trunk/src/group_template.hpp
===================================================================
--- /XIOS3/trunk/src/group_template.hpp	(revision 2613)
+++ /XIOS3/trunk/src/group_template.hpp	(revision 2614)
@@ -51,4 +51,6 @@
          virtual void parse(xml::CXMLNode & node);
          virtual void parse(xml::CXMLNode & node, bool withAttr);
+         virtual void parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList);
+
          virtual void parseChild(xml::CXMLNode & node);
         
Index: /XIOS3/trunk/src/group_template_impl.hpp
===================================================================
--- /XIOS3/trunk/src/group_template_impl.hpp	(revision 2613)
+++ /XIOS3/trunk/src/group_template_impl.hpp	(revision 2614)
@@ -37,131 +37,4 @@
    { /* Ne rien faire de plus */ }
    
-   ///--------------------------------------------------------------
-/*
-   template <class U, class V, class W>
-      void CGroupTemplate<U, V, W>::toBinary(StdOStream & os) const
-   {
-      SuperClass::toBinary(os);
-      
-      const StdSize grpnb = this->groupList.size();
-      const StdSize chdnb = this->childList.size();
-      ENodeType cenum = U::GetType();
-      ENodeType genum = V::GetType();
-      
-      os.write (reinterpret_cast<const char*>(&grpnb) , sizeof(StdSize));
-      os.write (reinterpret_cast<const char*>(&chdnb) , sizeof(StdSize));      
-      
-      typename std::vector<V*>::const_iterator  
-         itg = this->groupList.begin(), endg = this->groupList.end();
-      typename std::vector<U*>::const_iterator 
-         itc = this->childList.begin(), endc = this->childList.end();
-            
-      for (; itg != endg; itg++)
-      { 
-         V* group = *itg;
-         bool hid = group->hasId();
-         
-         os.write (reinterpret_cast<const char*>(&genum), sizeof(ENodeType));      
-         os.write (reinterpret_cast<const char*>(&hid), sizeof(bool));
-         
-         if (hid)
-         {
-            const StdString & id = group->getId();
-            const StdSize size   = id.size();
-               
-            os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize));
-            os.write (id.data(), size * sizeof(char));         
-         }              
-         group->toBinary(os);
-      }
-            
-      for (; itc != endc; itc++)
-      { 
-         U* child = *itc;
-         bool hid = child->hasId();
-         
-         os.write (reinterpret_cast<const char*>(&cenum), sizeof(ENodeType));
-         os.write (reinterpret_cast<const char*>(&hid), sizeof(bool));
-         
-         if (hid)
-         {
-            const StdString & id = child->getId();
-            const StdSize size   = id.size();
-               
-            os.write (reinterpret_cast<const char*>(&size), sizeof(StdSize));
-            os.write (id.data(), size * sizeof(char));         
-         }         
-         child->toBinary(os);
-      }
-      
-   }
-   
-   template <class U, class V, class W>
-      void CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)
-   {
-      SuperClass::fromBinary(is);
-      
-      V* group_ptr = (this->hasId())
-         ? V::get(this->getId())
-         : V::get((V*)this);
-      
-      StdSize grpnb = 0;
-      StdSize chdnb = 0;
-      ENodeType renum = Unknown;
-      
-      is.read (reinterpret_cast<char*>(&grpnb), sizeof(StdSize));
-      is.read (reinterpret_cast<char*>(&chdnb), sizeof(StdSize));
-      
-      for (StdSize i = 0; i < grpnb; i++)
-      {
-         bool hid = false;
-         is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType));
-         is.read (reinterpret_cast<char*>(&hid), sizeof(bool));
-         
-         if (renum != V::GetType())
-            ERROR("CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)",
-                  << "[ renum = " << renum << "] Bad type !");
-                        
-         if (hid)
-         {
-            StdSize size  = 0;
-            is.read (reinterpret_cast<char*>(&size), sizeof(StdSize));
-            StdString id(size, ' ');
-            is.read (const_cast<char *>(id.data()), size * sizeof(char));
-            CGroupFactory::CreateGroup(group_ptr->getShared(), id)->fromBinary(is);
-         }
-         else
-         {
-            CGroupFactory::CreateGroup(group_ptr->getShared())->fromBinary(is);
-         }
-      }
-      
-      for (StdSize j = 0; j < chdnb; j++)
-      {
-         bool hid = false;
-         is.read (reinterpret_cast<char*>(&renum), sizeof(ENodeType));
-         is.read (reinterpret_cast<char*>(&hid), sizeof(bool));
-         
-         if (renum != U::GetType())
-            ERROR("CGroupTemplate<U, V, W>::fromBinary(StdIStream & is)",
-                  << "[ renum = " << renum << "] Bad type !");
-                  
-         if (hid)
-         {
-            StdSize size  = 0;
-            is.read (reinterpret_cast<char*>(&size), sizeof(StdSize));
-            StdString id(size, ' ');
-            is.read (const_cast<char *>(id.data()), size * sizeof(char));
-            CGroupFactory::CreateChild(group_ptr->getShared(), id)->fromBinary(is);            
-         }
-         else
-         {
-            CGroupFactory::CreateChild(group_ptr->getShared())->fromBinary(is);
-         }   
-      }
-   }
-*/
-   //--------------------------------------------------------------
-
    template <class U, class V, class W>
       StdString CGroupTemplate<U, V, W>::toString(void) const
@@ -255,12 +128,4 @@
 
    template <class U, class V, class W>
-      void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node)
-   { 
-      this->parse(node, true); 
-   }
-   
-   //---------------------------------------------------------------
-   
-   template <class U, class V, class W>
       void CGroupTemplate<U, V, W>::solveDescInheritance(bool apply, const CAttributeMap * const parent)
    {
@@ -319,27 +184,5 @@
    { /* Ne rien faire de plus */ }
    
-//   template <class U, class V, class W>
-//   bool CGroupTemplate<U, V, W>::has(const string& id) 
-//   {
-//       return CObjectFactory::HasObject<V>(id) ;
-//   }
-
-//   template <class U, class V, class W>
-//   std::shared_ptr<V> CGroupTemplate<U, V, W>::get(const string& id) 
-//   {
-//       return CObjectFactory::GetObject<V>(id) ;
-//   }
-
-//   template <class U, class V, class W>
-//   std::shared_ptr<V> CGroupTemplate<U, V, W>::get() 
-//   {
-//       return CObjectFactory::GetObject<V>(this) ;
-//   }
-   
-//   template <class U, class V, class W>
-//   std::shared_ptr<V> CGroupTemplate<U, V, W>::create(const string& id) 
-//   {
-//       return CObjectFactory::CreateObject<V>(id) ;
-//   }
+
    ///--------------------------------------------------------------
 
@@ -470,4 +313,17 @@
 
    template <class U, class V, class W>
+   void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node)
+   { 
+      this->parse(node, true); 
+   }
+   
+   template <class U, class V, class W>
+   void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList)
+   {
+     ERROR("void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList)",
+                     <<"must not be called by this kind of object : "<<GetName() ) ;
+   }
+
+   template <class U, class V, class W>
       void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)
    {
@@ -478,16 +334,5 @@
       {
          CGroupTemplate<U, V, W>::SuperClass::parse(node);
-         if (attributes.end() != attributes.find("src"))
-         {
-            StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in );
-            if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 )
-               ERROR("void CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)",
-                     <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" );
-            
-            if (!ifs.good())
-               ERROR("CGroupTemplate<U, V, W>::parse(xml::CXMLNode & node, bool withAttr)",
-                     << "[ filename = " << attributes["src"] << " ] Bad xml stream !");
-            xml::CXMLParser::ParseInclude(ifs, attributes["src"].c_str(), *this);
-         }
+         if (attributes.end() != attributes.find("src")) xml::CXMLParser::ParseInclude(attributes["src"].c_str(), *this);
       }
 
Index: /XIOS3/trunk/src/mpi_tools.hpp
===================================================================
--- /XIOS3/trunk/src/mpi_tools.hpp	(revision 2613)
+++ /XIOS3/trunk/src/mpi_tools.hpp	(revision 2614)
@@ -12,4 +12,7 @@
   template<typename T> 
   MPI_Datatype MPI_GetType(void) ;
+
+  template<> 
+  MPI_Datatype MPI_GetType<bool>(void) ;
 
   template<>
Index: /XIOS3/trunk/src/node/context.cpp
===================================================================
--- /XIOS3/trunk/src/node/context.cpp	(revision 2613)
+++ /XIOS3/trunk/src/node/context.cpp	(revision 2614)
@@ -164,18 +164,6 @@
       xml::THashAttributes attributes = node.getAttributes();
 
-      if (attributes.end() != attributes.find("src"))
-      {
-         StdIFStream ifs ( attributes["src"].c_str() , StdIFStream::in );
-         if ( (ifs.rdstate() & std::ifstream::failbit ) != 0 )
-         {
-            ERROR("void CContext::parse(xml::CXMLNode & node)",
-                  <<endl<< "Can not open <"<<attributes["src"].c_str()<<"> file" );
-         }
-         if (!ifs.good())
-            ERROR("CContext::parse(xml::CXMLNode & node)",
-                  << "[ filename = " << attributes["src"] << " ] Bad xml stream !");
-         xml::CXMLParser::ParseInclude(ifs, attributes["src"], *this);
-      }
-
+      if (attributes.end() != attributes.find("src")) xml::CXMLParser::ParseInclude(attributes["src"], *this);
+      
       if (node.getElementName().compare(CContext::GetName()))
          DEBUG("Le noeud is wrong defined but will be considered as a context !");
@@ -211,4 +199,66 @@
          } while (node.goToNextElement());
 
+         node.goToParentElement(); // Retour au parent
+      }
+   }
+   CATCH_DUMP_ATTR
+
+
+   template <>
+   void CGroupTemplate<CContext, CContextGroup, CContextAttributes>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList)
+   TRY
+   {
+      StdString name = node.getElementName();
+      xml::THashAttributes attributes = node.getAttributes();
+      CGroupTemplate<CContext, CContextGroup, CContextAttributes>::SuperClass::parse(node);
+      if (attributes.end() != attributes.find("src")) xml::CXMLParser::ParseInclude(attributes["src"].c_str(), *this, parseContextList);
+
+      if (!(node.goToChildElement()))
+      {
+        // no children ?
+      }
+      else
+      {
+        do // Parcours pour traitement.
+        { 
+
+          StdString name = node.getElementName();
+          attributes.clear();
+          attributes = node.getAttributes();
+
+          if (name.compare(CContextGroup::GetName()) == 0)
+          {
+            CContextGroup contextGroup ;
+            contextGroup.parse(node, true, parseContextList) ;
+            continue;
+          }
+
+          if (name.compare(CContext::GetName()) == 0)
+          {
+            if (attributes.end() == attributes.find("id"))
+            {
+              DEBUG("The context will not be processed because it is not identified (missing id)");
+              continue;
+            }
+            else
+            {  
+              if (parseContextList.empty() || parseContextList.count(attributes["id"]) > 0)
+              {
+                CContext::setCurrent(attributes["id"]) ;
+                CContext* context = CContext::create(attributes["id"]);
+                context->parse(node);
+                attributes.clear();
+              }
+              continue;
+            }
+          }
+
+          DEBUG(<< "Dans le contexte \'" << CContext::getCurrent()->getId()
+                << "\', un objet de type \'" << CContextGroup::GetName()
+                << "\' ne peut contenir qu'un objet de type \'" << CContextGroup::GetName()
+                << "\' ou de type \'" << CContext::GetName()
+                << "\' (reÃ§u : " << name << ") !");
+
+         } while (node.goToNextElement());
          node.goToParentElement(); // Retour au parent
       }
Index: /XIOS3/trunk/src/node/context.hpp
===================================================================
--- /XIOS3/trunk/src/node/context.hpp	(revision 2613)
+++ /XIOS3/trunk/src/node/context.hpp	(revision 2614)
@@ -409,4 +409,7 @@
    DECLARE_GROUP(CContext);
 
+   template <>
+   void CGroupTemplate<CContext, CContextGroup, CContextAttributes>::parse(xml::CXMLNode & node, bool withAttr, const std::set<StdString>& parseContextList) ;
+
    ///--------------------------------------------------------------
 
Index: /XIOS3/trunk/src/string_tools.hpp
===================================================================
--- /XIOS3/trunk/src/string_tools.hpp	(revision 2613)
+++ /XIOS3/trunk/src/string_tools.hpp	(revision 2614)
@@ -9,4 +9,5 @@
 {
   std::vector<std::string> splitRegex(const std::string& input, const std::string& regex) ;
+  std::string strTrim(const std::string& input) ;
 
   inline std::vector<std::string> splitRegex(const std::string& input, const std::string& regex)
@@ -20,4 +21,8 @@
   }
 
+  inline std::string strTrim(const std::string& input)
+  {
+    return std::regex_replace(input, std::regex("^ +| +$"), "$1");
+  }
 }
 #endif
Index: /XIOS3/trunk/src/xml_parser.cpp
===================================================================
--- /XIOS3/trunk/src/xml_parser.cpp	(revision 2613)
+++ /XIOS3/trunk/src/xml_parser.cpp	(revision 2614)
@@ -11,4 +11,35 @@
    namespace xml
    {
+      string CXMLParser::currentIncludePath_="." ;
+
+      string CXMLParser::updateIncludePath(const string& filePath)
+      {
+        string path = strTrim(filePath) ;
+        vector<string> match=splitRegex(path+'/',"/" ) ;
+
+        // check if empty path
+        bool isEmpty=true ;
+        for(auto& m : match) 
+          if (!m.empty())
+          {
+            isEmpty=false ;
+            break ;
+          }
+
+        if (isEmpty) ERROR("string CXMLParser::updatePath(const string& filePath)",
+                     << "File path to include an new XML is empty :'"<<filePath<<"'" );
+
+        if (match.back().empty()) ERROR("string CXMLParser::updatePath(const string& filePath)",
+                     << "File path to include an new XML must not be a directory but a file :'"<<filePath<<"'" );
+        bool isAbsolutePath = match.front().empty() ;
+        
+        if (isAbsolutePath) currentIncludePath_="" ;
+        for(int i=0; i<match.size()-1; ++i) if (! match[i].empty()) currentIncludePath_ = currentIncludePath_ + "/" + match[i] ;
+        
+        string finalPath = currentIncludePath_ + "/" + match.back() ;
+
+        return finalPath ;
+      }
+
       /// ////////////////////// DÃ©finitions ////////////////////// ///
 
@@ -52,46 +83,8 @@
                      << "Root element should be named simulation (actual = \'"
                      << node.getElementName() << "\')!");
-
-            std::set<StdString>::iterator it;
-            std::set<StdString>::const_iterator itE = parseContextList.end();
-            bool isParseAll = (parseContextList.empty());
             try
             {
-              if (node.goToChildElement())
-              {
-                 do
-                 {
-                    CContextGroup* group_context = CContext::getRoot() ;
-
-                    attributes = node.getAttributes();
-
-                    if (attributes.end() == attributes.find("id"))
-                    {
-                       DEBUG("The context will not be processed because it is not identified (missing id)");
-                       continue;
-                    }
-
-                    CContext::setCurrent(attributes["id"]) ;
-
-                    if (isParseAll)
-                    {
-                      CContext* context = CContext::create(attributes["id"]);
-                      context->parse(node);
-
-                      attributes.clear();
-                    }
-                    else
-                    {
-                      it = parseContextList.find(attributes["id"]);
-                      if (itE != it)
-                      {
-                        CContext* context = CContext::create(*it);
-                        context->parse(node);
-
-                        attributes.clear();
-                      }
-                    }
-                 } while (node.goToNextElement());
-              }
+              CContextGroup* rootContext = CContext::getRoot() ;
+              rootContext->parse(node, true, parseContextList) ;
             }
             catch(CException& e)
Index: /XIOS3/trunk/src/xml_parser.hpp
===================================================================
--- /XIOS3/trunk/src/xml_parser.hpp	(revision 2613)
+++ /XIOS3/trunk/src/xml_parser.hpp	(revision 2614)
@@ -21,30 +21,17 @@
             static void ParseString(const StdString & xmlContent);
             static void ParseStream(StdIStream & stream, const string& fluxId, const std::set<StdString>& parseList);
+            
+            template <class T> 
+            static void ParseInclude(const string& fluxId, T & object);
+  
             template <class T>
-               static void ParseInclude(StdIStream & stream, const string& fluxId, T & object);
+            static void ParseInclude(const string& fluxId, T & object, const std::set<StdString>& parseContextList);
 
+            static string updateIncludePath(const string& filePath) ;
+
+         private:
+            static string currentIncludePath_ ; // current include path for XML file
       }; //class CXMLParser
-/*
-      template <class T>
-         void CXMLParser::ParseInclude(StdIStream & stream, T& object)
-      {
-         StdOStringStream oss;
-         while(!stream.eof() && !stream.fail ())
-            oss.put(stream.get());
-         try
-         {
-            const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 );
-            rapidxml::xml_document<char> doc;
-            doc.parse<0>(const_cast<char*>(xmlcontent.c_str()));
-            CXMLNode node(doc.first_node());
-            object.parse(node);
-         }
-         catch (rapidxml::parse_error & exc)
-         {
-            ERROR("CXMLParser::ParseStream(StdIStream & stream)",
-                  << "RapidXML error : " << exc.what() << " !");
-         }
-      }
-*/
+
    }// namespace xml
 } // namespace xios
Index: /XIOS3/trunk/src/xml_parser_decl.cpp
===================================================================
--- /XIOS3/trunk/src/xml_parser_decl.cpp	(revision 2613)
+++ /XIOS3/trunk/src/xml_parser_decl.cpp	(revision 2614)
@@ -7,8 +7,8 @@
   namespace xml
   {
-    template void CXMLParser::ParseInclude<CContext>(StdIStream & stream, const string& fluxId, CContext& object) ;
+    template void CXMLParser::ParseInclude<CContext>(const string& fluxId, CContext& object) ;
 
  #   define macro(T) \
-    template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(StdIStream & stream, const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object) ;
+    template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object) ;
 
     macro( Context )
@@ -47,5 +47,10 @@
     macro( RedistributeAxis )
     macro( RedistributeScalar )
+#   undef macro
 
+#   define macro(T) \
+    template void CXMLParser::ParseInclude< CGroupTemplate<C##T, C##T##Group, C##T##Attributes> >(const string& fluxId, CGroupTemplate<C##T, C##T##Group, C##T##Attributes>& object, const std::set<StdString>& parseContextList) ;
+    macro( Context )
+#   undef macro
   }
 }
Index: /XIOS3/trunk/src/xml_parser_impl.hpp
===================================================================
--- /XIOS3/trunk/src/xml_parser_impl.hpp	(revision 2613)
+++ /XIOS3/trunk/src/xml_parser_impl.hpp	(revision 2614)
@@ -9,6 +9,18 @@
    namespace xml
    {
-     template <class T> void CXMLParser::ParseInclude(StdIStream & stream, const string& fluxId,  T& object)
+     template <class T> void CXMLParser::ParseInclude(const string& fluxId,  T& object)
       {
+         string parentPath = currentIncludePath_ ;        
+         string filePath = updateIncludePath(fluxId) ;
+
+         StdIFStream stream(filePath, StdIFStream::in ) ;
+         if ( (stream.rdstate() & std::ifstream::failbit ) != 0 )
+               ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId,  T& object)",
+                     <<endl<< "Can not open <"<<fluxId<<"> file" );
+            
+         if (!stream.good())
+               ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId,  T& object)",
+                     << "[ filename = " << fluxId << " ] Bad xml stream !");
+
          StdOStringStream oss;
          while(!stream.eof() && !stream.fail ()) oss.put(stream.get());
@@ -20,4 +32,5 @@
             CXMLNode node(doc.first_node());
             object.parse(node);
+            currentIncludePath_ = parentPath ;    
          }
          catch (rapidxml::parse_error & exc)
@@ -44,4 +57,55 @@
       }
 
+      template <class T> void CXMLParser::ParseInclude(const string& fluxId,  T& object, const std::set<StdString>& parseContextList)
+      {
+         
+         string parentPath = currentIncludePath_ ;   // save current path     
+         string filePath = updateIncludePath(fluxId) ; // path is updated
+
+         StdIFStream stream(filePath, StdIFStream::in ) ;
+         if ( (stream.rdstate() & std::ifstream::failbit ) != 0 )
+               ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId,  T& object)",
+                     <<endl<< "Can not open <"<<fluxId<<"> file" );
+            
+         if (!stream.good())
+               ERROR("template <class T> void CXMLParser::ParseInclude(const string& fluxId,  T& object)",
+                     << "[ filename = " << fluxId << " ] Bad xml stream !");
+
+
+         StdOStringStream oss;
+         while(!stream.eof() && !stream.fail ()) oss.put(stream.get());
+         const StdString xmlcontent( oss.str(), 0, oss.str().size()-1 );
+         try
+         {
+            rapidxml::xml_document<char> doc;
+            doc.parse<0>(const_cast<char*>(xmlcontent.c_str()));
+            CXMLNode node(doc.first_node());
+            object.parse(node, true, parseContextList);
+            currentIncludePath_ = parentPath ;    // restore include path
+         }
+         catch (rapidxml::parse_error & exc)
+         {
+             const char* ptr = exc.where<char>() ;
+            const char* begin = xmlcontent.c_str() ;
+            const char* content=oss.str().c_str() ;
+            size_t pos=ptr-begin ;
+            int lineNumber = 1 ;
+            int columnNumber = 0 ;
+            const char* line;
+            const char* endLine;
+            
+            for(const char* i=content;i<content+pos; ++i, ++columnNumber) if (*i=='\n') { lineNumber++ ; line=i ; columnNumber=0 ;}
+            for(endLine=content+pos; *endLine!='\n' && *endLine!='\0' ; ++endLine) ;
+            string strLine(line,endLine-line) ;
+                  
+            ERROR("CXMLParser::ParseStream(StdIStream & stream)", << endl
+                  << "Error is occuring when parsing XML flux from <"<<fluxId<<"> at character "<< pos<<" line "<<lineNumber<<" column "<< columnNumber<< endl
+                  << strLine<<endl
+                  << string(columnNumber-1,'x')<<'^'<<endl)
+//                  <<" Error : " << exc.what() )
+         }
+      }
+
+
    } // namespace xml
 } // namespace xios
