diff --git a/DDCore/CMakeLists.txt b/DDCore/CMakeLists.txt
index c84d79c58623da628c4adf8809e380ded0f2e95d..d16d6adf9414c83e68607db2a6480850f5f5dfda 100644
--- a/DDCore/CMakeLists.txt
+++ b/DDCore/CMakeLists.txt
@@ -2,11 +2,9 @@ cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
 
 project(DDCore)
 
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include 
-                    ${ROOT_INCLUDE_DIR}
-                    ${XERCESC_INCLUDE_DIR})
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIR})
 
-file(GLOB sources src/*.cpp src/Evaluator/*.cpp)
+file(GLOB sources src/*.cpp src/Evaluator/*.cpp src/XML/*.cpp)
 file(GLOB plugin_sources src/plugins/*.cpp)
 
 if(DD4HEP_USE_PYROOT)
@@ -19,17 +17,13 @@ if(DD4HEP_USE_PYROOT)
   set(libraries  ${libraries} PyROOT)
 endif()
 
-if(DD4HEP_USE_XERCESC)
-  file(GLOB xmlsources src/XML/*.cpp)
-  list(APPEND sources ${xmlsources})
-  add_definitions(-DDD4HEP_USE_XERCESC)
-endif()
+include(DD4hep_XML_setup)
 
 add_library(DD4hepCore SHARED ${sources})
-target_link_libraries(DD4hepCore ${ROOT_LIBRARIES} ${XERCESC_LIBRARIES} Geom Reflex ${libraries})
+target_link_libraries(DD4hepCore ${ROOT_LIBRARIES} ${XML_LIBRARIES} Geom Reflex ${libraries})
 
 add_library(DD4hepPlugins SHARED ${plugin_sources})
-target_link_libraries(DD4hepPlugins ${ROOT_LIBRARIES} ${XERCESC_LIBRARIES} DD4hepCore Geom Reflex ${libraries})
+target_link_libraries(DD4hepPlugins ${ROOT_LIBRARIES} ${XML_LIBRARIES} DD4hepCore Geom Reflex ${libraries})
 #---Rootmap generation--------------------------------------------------------------
 dd4hep_generate_rootmap(DD4hepPlugins)
 
diff --git a/DDCore/include/XML/XMLElements.h b/DDCore/include/XML/XMLElements.h
index f4775fd809ed0122e30a45b48185bc043d3a417a..7916eaba459b9717181343acc2463788867b542e 100644
--- a/DDCore/include/XML/XMLElements.h
+++ b/DDCore/include/XML/XMLElements.h
@@ -502,6 +502,8 @@ namespace DD4hep {
       operator DOC() const   {  return m_doc; }
       /// Accessot to DOM document behaviour using arrow operator
       DOC operator->() const {  return m_doc; }
+      /// Accessot to DOM document behaviour
+      DOC ptr() const        {  return m_doc; }
       /// Access the ROOT eleemnt of the DOM document
       Handle_t  root() const;
 
diff --git a/DDCore/include/XML/config.h b/DDCore/include/XML/config.h
index d9ae580e39f88699db822b0086678c29cabd832a..81dd70ede4bd67e58b4a6e119bad80972be8c2b3 100644
--- a/DDCore/include/XML/config.h
+++ b/DDCore/include/XML/config.h
@@ -9,58 +9,37 @@
 #ifndef DD4HEP_XML_CONFIG_H
 #define DD4HEP_XML_CONFIG_H
 
-#define  __TIXML__
-
-#ifndef  __TIXML__
-
-/* Setup XML parsing for the use of Apache Xerces-C
- *
- * @author M.Frank
- */
-#include "xercesc/dom/DOMException.hpp"
-XERCES_CPP_NAMESPACE_BEGIN
-  class DOMElement;
-  class DOMDocument;
-  class DOMNodeList;
-  class DOMNode;
-  class DOMAttr;
-  class DOMException;
-XERCES_CPP_NAMESPACE_END
-namespace DD4hep { namespace XML {  
-    typedef XMLSize_t              XmlSize_t;
-    typedef XMLCh                  XmlChar;
-    typedef xercesc::DOMElement    XmlElement;
-    typedef xercesc::DOMDocument   XmlDocument;
-    typedef xercesc::DOMNodeList   XmlNodeList;
-    typedef xercesc::DOMNode       XmlNode;
-    typedef xercesc::DOMAttr       XmlAttr;
-    typedef xercesc::DOMException  XmlException;
-}}
-#define XML_IMPLEMENTATION_TYPE " Apache Xerces-C DOM Parser"
-#define XML_HEADER_DECLARATION
 
-#else  // __TIXML__
+#if      defined(DD4HEP_USE_TINYXML)
+#define  __TIXML__
+#endif
 
 #include <cstdlib>
-/* Setup XML parsing for the use of TiXml
+
+/* Setup XML parsing for the use of Apache Xerces-C and TiXml
  *
  * @author M.Frank
  */
-class TiXmlElement;
-class TiXmlDocument;
-class TiXmlNode;
-class TiXmlAttribute;
 namespace DD4hep { namespace XML {
-    typedef std::size_t     XmlSize_t;
-    typedef char            XmlChar;
-    typedef TiXmlElement    XmlElement;
-    typedef TiXmlDocument   XmlDocument;
-    typedef void            XmlNodeList;
-    typedef TiXmlNode       XmlNode;
-    typedef TiXmlAttribute  XmlAttr;
+    class XmlElement;
+    class XmlDocument;
+    class XmlNodeList;
+    class XmlNode;
+    class XmlAttr;
+    typedef std::size_t    XmlSize_t;
+#ifdef  __TIXML__
+    typedef char           XmlChar;
+#else
+    typedef unsigned short XmlChar;
+#endif
 }}
+
+#ifdef  __TIXML__
 #define XML_IMPLEMENTATION_TYPE " TinyXML DOM mini-parser   "
 #define XML_HEADER_DECLARATION  "<?xml version=\"1.0\" encoding=\"UTF-8\">\n"
-#endif // __TIXML__
+#else   // Xerces-C
+#define XML_IMPLEMENTATION_TYPE " Apache Xerces-C DOM Parser"
+#define XML_HEADER_DECLARATION
+#endif  // __TIXML__
 
 #endif // DD4HEP_XML_CONFIG_H
diff --git a/DDCore/src/LCDDImp.cpp b/DDCore/src/LCDDImp.cpp
index f5a3b3ab4b967772ea6190a9e025776b0d08d50f..26eb3c3b492a6bd2c82a4725a2bcb2d7b7a93a1c 100644
--- a/DDCore/src/LCDDImp.cpp
+++ b/DDCore/src/LCDDImp.cpp
@@ -22,11 +22,16 @@
 #include "TGeoShape.h"
 #include "TClass.h"
 #include "Reflex/PluginService.h"
+#include "XML/DocumentHandler.h"
 
 #if DD4HEP_USE_PYROOT
   #include "TPython.h"
-#elif DD4HEP_USE_XERCESC
-  #include "XML/DocumentHandler.h"
+#endif
+#ifndef __TIXML__
+#include "xercesc/dom/DOMException.hpp"
+namespace DD4hep { namespace XML {  
+  typedef xercesc::DOMException  XmlException;
+}}
 #endif
 
 using namespace DD4hep::Geometry;
@@ -234,7 +239,7 @@ void LCDDImp::fromXML(const string& xmlfile, LCDDBuildType build_type) {
   TPython::Exec("import lcdd");
   cmd = "lcdd.fromXML('" + xmlfile + "')";
   TPython::Exec(cmd.c_str());  
-#elif DD4HEP_USE_XERCESC
+#else
   XML::Handle_t xml_root = XML::DocumentHandler().load(xmlfile).root();
   string tag = xml_root.tag();
   try {
@@ -250,14 +255,14 @@ void LCDDImp::fromXML(const string& xmlfile, LCDDBuildType build_type) {
       throw runtime_error("Failed to parse the XML file "+xmlfile+" with the plugin "+type);
     }
   }
-  catch(const exception& e)  {
-    cout << "Exception:" << e.what() << endl;
-    throw runtime_error("Exception:\""+string(e.what())+"\" while parsing "+xmlfile);
-  }
   catch(const XML::XmlException& e)  {
     cout << "XML-DOM Exception:" << XML::_toString(e.msg) << endl;
     throw runtime_error("XML-DOM Exception:\""+XML::_toString(e.msg)+"\" while parsing "+xmlfile);
   } 
+  catch(const exception& e)  {
+    cout << "Exception:" << e.what() << endl;
+    throw runtime_error("Exception:\""+string(e.what())+"\" while parsing "+xmlfile);
+  }
   catch(...)  {
     cout << "UNKNOWN Exception" << endl;
     throw runtime_error("UNKNOWN exception while parsing "+xmlfile);
@@ -285,6 +290,10 @@ void LCDDImp::apply(const char* factory_type, int argc, char** argv)   {
       throw runtime_error("apply-plugin: Failed to execute plugin "+fac);
     }
   }
+  catch(const XML::XmlException& e)  {
+    cout << "XML-DOM Exception:" << XML::_toString(e.msg) << endl;
+    throw runtime_error("XML-DOM Exception:\""+XML::_toString(e.msg)+"\" with plugin:"+fac);
+  } 
   catch(const exception& e)  {
     cout << "Exception:" << e.what() << endl;
     throw runtime_error("Exception:\""+string(e.what())+"\" with plugin:"+fac);
diff --git a/DDCore/src/XML/DocumentHandler.cpp b/DDCore/src/XML/DocumentHandler.cpp
index eb5492f1ef9f6e370aed539db739756641fb62e1..c113328ad3ce0582339d59a9b2d2a2118c355d05 100644
--- a/DDCore/src/XML/DocumentHandler.cpp
+++ b/DDCore/src/XML/DocumentHandler.cpp
@@ -25,37 +25,31 @@ using namespace DD4hep::XML;
 #include "xercesc/sax/ErrorHandler.hpp"
 using namespace xercesc;
 
-namespace {
-
-  XercesDOMParser* make_parser(xercesc::ErrorHandler* err_handler=0)   {
-    XercesDOMParser* parser = new XercesDOMParser;
-    parser->setValidationScheme(XercesDOMParser::Val_Auto);
-    parser->setValidationSchemaFullChecking(true);
-    if ( err_handler ) {
-      parser->setErrorHandler(err_handler);
+namespace DD4hep { namespace XML {
+  namespace {
+    XercesDOMParser* make_parser(xercesc::ErrorHandler* err_handler=0)   {
+      XercesDOMParser* parser = new XercesDOMParser;
+      parser->setValidationScheme(XercesDOMParser::Val_Auto);
+      parser->setValidationSchemaFullChecking(true);
+      if ( err_handler ) {
+	parser->setErrorHandler(err_handler);
+      }
+      parser->setDoNamespaces(true);
+      parser->setDoSchema(true);
+      return parser;
     }
-    parser->setDoNamespaces(true);
-    parser->setDoSchema(true);
-    return parser;
-  }
 
-  Document parse_document(const void* bytes, size_t length, xercesc::ErrorHandler* err_handler)   {
-    auto_ptr<XercesDOMParser> parser(make_parser(err_handler));
-    MemBufInputSource src((const XMLByte*)bytes,length,"memory");
-    parser->setValidationSchemaFullChecking(true);
-    parser->parse(src);
-    DOMDocument* doc = parser->adoptDocument();
-    doc->setXmlStandalone(true);
-    doc->setStrictErrorChecking(true);
-    return doc;
+    Document parse_document(const void* bytes, size_t length, xercesc::ErrorHandler* err_handler)   {
+      auto_ptr<XercesDOMParser> parser(make_parser(err_handler));
+      MemBufInputSource src((const XMLByte*)bytes,length,"memory");
+      parser->setValidationSchemaFullChecking(true);
+      parser->parse(src);
+      DOMDocument* doc = parser->adoptDocument();
+      doc->setXmlStandalone(true);
+      doc->setStrictErrorChecking(true);
+      return (XmlDocument*)doc;
+    }
   }
-
-}
-
-namespace DD4hep { namespace XML {
-
-  typedef const string& CSTR;
-
   struct DocumentErrorHandler : public ErrorHandler, public DOMErrorHandler    {
     /// Constructor
     DocumentErrorHandler()  {}
@@ -71,63 +65,62 @@ namespace DD4hep { namespace XML {
   };
   bool DocumentErrorHandler::handleError(const DOMError& domError)  {
     switch(domError.getSeverity()) {
-      case DOMError::DOM_SEVERITY_WARNING:
-        cout << "DOM WARNING: ";
-        break;
-      case DOMError::DOM_SEVERITY_ERROR:
-        cout << "DOM ERROR:   ";
-        break;
-      case DOMError::DOM_SEVERITY_FATAL_ERROR:
-        cout << "DOM FATAL:   ";
-        break;
-      default:
-        cout << "DOM UNKNOWN: ";
-        return false;
+    case DOMError::DOM_SEVERITY_WARNING:
+      cout << "DOM WARNING: ";
+      break;
+    case DOMError::DOM_SEVERITY_ERROR:
+      cout << "DOM ERROR:   ";
+      break;
+    case DOMError::DOM_SEVERITY_FATAL_ERROR:
+      cout << "DOM FATAL:   ";
+      break;
+    default:
+      cout << "DOM UNKNOWN: ";
+      return false;
     }
     cout << _toString(domError.getType()) << ": " << _toString(domError.getMessage()) << endl;
     DOMLocator* loc = domError.getLocation();
     if ( loc )  {
       cout << "Location: Line:" << loc->getLineNumber()
-        << " Column:" << loc->getColumnNumber() << endl;
+	   << " Column:" << loc->getColumnNumber() << endl;
     }
     return false;
   }
   void DocumentErrorHandler::error(const SAXParseException& e)  {
     string m(_toString(e.getMessage()));
     if (m.find("The values for attribute 'name' must be names or name tokens")!=string::npos ||
-      m.find("The values for attribute 'ID' must be names or name tokens")!=string::npos   ||
-      m.find("for attribute 'name' must be Name or Nmtoken")!=string::npos                 ||
-      m.find("for attribute 'ID' must be Name or Nmtoken")!=string::npos                   ||
-      m.find("for attribute 'name' is invalid Name or NMTOKEN value")!=string::npos        ||
-      m.find("for attribute 'ID' is invalid Name or NMTOKEN value")!=string::npos      )
+	m.find("The values for attribute 'ID' must be names or name tokens")!=string::npos   ||
+	m.find("for attribute 'name' must be Name or Nmtoken")!=string::npos                 ||
+	m.find("for attribute 'ID' must be Name or Nmtoken")!=string::npos                   ||
+	m.find("for attribute 'name' is invalid Name or NMTOKEN value")!=string::npos        ||
+	m.find("for attribute 'ID' is invalid Name or NMTOKEN value")!=string::npos      )
       return;
     string sys(_toString(e.getSystemId()));
     cout << "Error at file \""  << sys
-      << "\", line " << e.getLineNumber() << ", column " << e.getColumnNumber() << endl
-      << "Message: " << m << endl;
+	 << "\", line " << e.getLineNumber() << ", column " << e.getColumnNumber() << endl
+	 << "Message: " << m << endl;
   }
   void DocumentErrorHandler::fatalError(const SAXParseException& e)  {
     string m(_toString(e.getMessage()));
     string sys(_toString(e.getSystemId()));
     cout << "Fatal Error at file \"" << sys
-      << "\", line " << e.getLineNumber() << ", column " << e.getColumnNumber() << endl
-      << "Message: " << m << endl;
+	 << "\", line " << e.getLineNumber() << ", column " << e.getColumnNumber() << endl
+	 << "Message: " << m << endl;
     //throw runtime_error( "Standard pool exception : Fatal Error on the DOM Parser" );
   }
-}}
-
 
-void DD4hep::XML::dumpTree(xercesc::DOMDocument* doc)  {
-  DOMImplementation *imp = DOMImplementationRegistry::getDOMImplementation(Strng_t("LS"));
-  XMLFormatTarget   *tar = new StdOutFormatTarget();
-  DOMLSOutput       *out = imp->createLSOutput();
-  DOMLSSerializer   *wrt = imp->createLSSerializer();
-  out->setByteStream(tar);
-  wrt->getDomConfig()->setParameter(Strng_t("format-pretty-print"), true);
-  wrt->write(doc, out);
-  out->release();
-  wrt->release();
-}
+  void dumpTree(xercesc::DOMDocument* doc)  {
+    DOMImplementation *imp = DOMImplementationRegistry::getDOMImplementation(Strng_t("LS"));
+    XMLFormatTarget   *tar = new StdOutFormatTarget();
+    DOMLSOutput       *out = imp->createLSOutput();
+    DOMLSSerializer   *wrt = imp->createLSSerializer();
+    out->setByteStream(tar);
+    wrt->getDomConfig()->setParameter(Strng_t("format-pretty-print"), true);
+    wrt->write(doc, out);
+    out->release();
+    wrt->release();
+  }
+}}
 
 /// Default constructor of a document handler using XercesC
 DocumentHandler::DocumentHandler() :  m_errHdlr(new DocumentErrorHandler())  {
@@ -137,9 +130,9 @@ DocumentHandler::DocumentHandler() :  m_errHdlr(new DocumentErrorHandler())  {
 DocumentHandler::~DocumentHandler()  {
 }
 
-
 Document DocumentHandler::load(Handle_t base, const XMLCh* fname)  const  {
-  xercesc::XMLURL base_url(base->getBaseURI());
+  xercesc::DOMElement* e = (xercesc::DOMElement*)base.ptr();
+  xercesc::XMLURL base_url(e->getBaseURI());
   xercesc::XMLURL ref_url(base_url,fname);
   return load(_toString(ref_url.getURLText()));
 }
@@ -165,7 +158,7 @@ Document DocumentHandler::load(const string& fname)  const  {
     }
   }
   cout << "Document succesfully parsed....." << endl;
-  return parser->adoptDocument();
+  return (XmlDocument*)parser->adoptDocument();
 }
 
 /// Parse a standalong XML string into a document.
@@ -177,7 +170,7 @@ Document DocumentHandler::parse(const char* bytes, size_t length)  const {
   DOMDocument* doc  = parser->adoptDocument();
   doc->setXmlStandalone(true);
   doc->setStrictErrorChecking(true);
-  return doc;
+  return (XmlDocument*)doc;
 }
 
 /// Write xml document to output file (stdout if file name empty)
@@ -192,7 +185,7 @@ int DocumentHandler::output(Document doc, const std::string& fname) const {
 
   out->setByteStream(tar);
   wrt->getDomConfig()->setParameter(Strng_t("format-pretty-print"), true);
-  wrt->write(doc, out);
+  wrt->write((xercesc::DOMDocument*)doc.ptr(), out);
   out->release();
   wrt->release();
   delete tar;
@@ -207,7 +200,23 @@ int DocumentHandler::output(Document doc, const std::string& fname) const {
 #endif
 #include <sys/stat.h>
 
-namespace DD4hep { namespace XML {  struct DocumentErrorHandler {};   }}
+namespace DD4hep { namespace XML {  
+  struct DocumentErrorHandler {};   
+  union Xml { 
+    Xml(void* ptr) : p(ptr) {}
+    Xml(const void* ptr) : cp(ptr) {}
+    void* p;
+    const void* cp;
+    TiXmlElement* e;
+    XmlElement* xe;
+    TiXmlAttribute* a;
+    Attribute  attr;
+    TiXmlNode* n;
+    TiXmlDocument* d;
+    XmlDocument* xd;
+  };
+
+}}
 
 namespace {
   static string _clean_fname(const string& s) {
@@ -229,7 +238,7 @@ Document DocumentHandler::load(Handle_t base, const XmlChar* fname)  const  {
   Element elt(base);
   // Poor man's URI handling. Xerces is much much better here
   if ( elt ) {
-    string bn = elt.document()->Value();
+    string bn = Xml(elt.document()).d->Value();
 #ifdef _WIN32
     char drive[_MAX_DRIVE], dir[_MAX_DIR], file[_MAX_FNAME], ext[_MAX_EXT];
     ::_splitpath(bn.c_str(),drive,dir,file,ext);
@@ -274,7 +283,7 @@ Document DocumentHandler::load(const string& fname)  const  {
   }
   if ( result ) {
     cout << "Document " << fname << " succesfully parsed....." << endl;
-    return doc;
+    return (XmlDocument*)doc;
   }
   delete doc;
   return 0;
@@ -285,7 +294,7 @@ Document DocumentHandler::parse(const char* doc_string, size_t length) const {
   TiXmlDocument* doc = new TiXmlDocument();
   try  {
     if ( 0 == doc->Parse(doc_string) ) {
-      return doc;
+      return (XmlDocument*)doc;
     }
     if ( doc->Error() ) {
       cout << "Unknown error whaile parsing XML document with TiXml:" << endl;
@@ -310,7 +319,8 @@ int DocumentHandler::output(Document doc, const std::string& fname) const {
     cout << "Failed to open output file:" << fname << endl;
     return 0;
   }
-  doc->Print(file);
+  TiXmlDocument* d = (TiXmlDocument*)doc.ptr();
+  d->Print(file);
   if ( !fname.empty() ) ::fclose(file);
   return 1;
 }
diff --git a/DDCore/src/XML/XMLElements.cpp b/DDCore/src/XML/XMLElements.cpp
index f9f4918675ba1e0ed905d5a42c15bdb948abeec2..15598f1a46c6943de6dc17b9a03cce2f70668647 100644
--- a/DDCore/src/XML/XMLElements.cpp
+++ b/DDCore/src/XML/XMLElements.cpp
@@ -7,18 +7,8 @@
 //
 //====================================================================
 // Framework include files
-#include "XML/XMLElements.h"
-
-#ifdef __TIXML__
-#include "XML/tinyxml.h"
-#else
-#include "xercesc/util/XMLString.hpp"
-#include "xercesc/dom/DOMElement.hpp"
-#include "xercesc/dom/DOMDocument.hpp"
-#include "xercesc/dom/DOMNodeList.hpp"
-#endif
-
 #include "XML/Evaluator.h"
+#include "XML/XMLElements.h"
 #include "XML/XMLTags.h"
 
 // C/C++ include files
@@ -29,61 +19,98 @@
 
 using namespace std;
 using namespace DD4hep::XML;
+#define INVALID_NODE ~0x0
 
 // Forward declarations
 namespace DD4hep  {
   XmlTools::Evaluator& evaluator();
 }
-
 // Static storage
 namespace {
   XmlTools::Evaluator& eval(DD4hep::evaluator());
 }
-#define INVALID_NODE ~0x0
 
-#ifdef __TIXML__
-#define ELEMENT_NODE_TYPE XmlNode::ELEMENT
+// Shortcuts
+#define _D(x)   Xml(x).d
+#define _E(x)   Xml(x).e
+#define _N(x)   Xml(x).n
+#define _L(x)   Xml(x).l
+#define _XE(x)  Xml(x).xe
+
+#ifdef DD4HEP_USE_TINYXML
+#include "XML/tinyxml.h"
+#define ELEMENT_NODE_TYPE TiXmlNode::ELEMENT
+#define getTagName          Value
+#define getTextContent      GetText
+#define getName             Name
+#define getValue            Value
+#define getNodeValue        Value
+#define getNodeType         Type
+#define setNodeValue        SetValue
+#define getParentNode       Parent()->ToElement
+#define getAttributeNode(x) AttributeNode(x)
+#define appendChild         LinkEndChild 
+#define getOwnerDocument    GetDocument  
+#define getDocumentElement  RootElement
+union Xml { 
+  Xml(const void* ptr) : p(ptr) {}
+  const void*     p;
+  TiXmlNode*      n;
+  TiXmlElement*   e;
+  TiXmlAttribute* a;
+  TiXmlDocument*  d;
+  XmlElement*    xe;
+};
+
 namespace {
-  Attribute    attribute_node(XmlElement* n, const XmlChar* t)       {  return n->AttributeNode(t);               }
-  const XmlChar* attribute_value(Attribute a)                        {  return a->Value();                        }
-  int          node_type(XmlNode* n)                                 {  return n->Type();                         }
-  XmlElement*  node_first(XmlElement* e, const XmlChar* t)           {  return e ? e->FirstChildElement(t) : 0;   }
-  size_t       node_count(XmlElement* e, const XmlChar* t) {
+  XmlElement*  node_first(XmlElement* e, const XmlChar* t) {
+    return e ? (XmlElement*)_E(e)->FirstChildElement(t) : 0;
+  }
+  size_t       node_count(XmlElement* elt, const XmlChar* t) {
     size_t cnt = 0;
+    TiXmlElement* e = Xml(elt).e;
     for(e=e->FirstChildElement(t);e; e=e->NextSiblingElement(t)) ++cnt;
     return cnt;
   }
 }
-XmlChar* DD4hep::XML::XmlString::replicate(const XmlChar* c)         {  return c ? ::strdup(c) : 0;               }
-XmlChar* DD4hep::XML::XmlString::transcode(const char* c)            {  return c ? ::strdup(c) : 0;               }
-void     DD4hep::XML::XmlString::release(char** p)                   {  if(p && *p) { ::free(*p); *p=0;}          }
+XmlChar* DD4hep::XML::XmlString::replicate(const XmlChar* c)  {  return c ? ::strdup(c) : 0;        }
+XmlChar* DD4hep::XML::XmlString::transcode(const char* c)     {  return c ? ::strdup(c) : 0;        }
+void     DD4hep::XML::XmlString::release(char** p)            {  if(p && *p) { ::free(*p); *p=0;}   }
 
 #else
-
-XmlChar* DD4hep::XML::XmlString::replicate(const XmlChar* c)         {  return xercesc::XMLString::replicate(c);  }
-char*    DD4hep::XML::XmlString::transcode(const XmlChar* c)         {  return xercesc::XMLString::transcode(c);  }
-XmlChar* DD4hep::XML::XmlString::transcode(const char* c)            {  return xercesc::XMLString::transcode(c);  }
-void     DD4hep::XML::XmlString::release(XmlChar** p)                {  return xercesc::XMLString::release(p);    }
-void     DD4hep::XML::XmlString::release(char** p)                   {  return xercesc::XMLString::release(p);    }
-
-#define ELEMENT_NODE_TYPE XmlNode::ELEMENT_NODE
+#include "xercesc/util/XMLString.hpp"
+#include "xercesc/dom/DOMElement.hpp"
+#include "xercesc/dom/DOMDocument.hpp"
+#include "xercesc/dom/DOMNodeList.hpp"
 #include "xercesc/dom/DOM.hpp"
+#define ELEMENT_NODE_TYPE xercesc::DOMNode::ELEMENT_NODE
+union Xml { 
+  Xml(const void* ptr) : p(ptr) {}
+  const void*           p;
+  xercesc::DOMNode*     n;
+  xercesc::DOMAttr*     a;
+  xercesc::DOMElement*  e;
+  xercesc::DOMDocument* d;
+  xercesc::DOMNodeList* l;
+  XmlElement*          xe;
+};
+
+XmlChar* DD4hep::XML::XmlString::replicate(const XmlChar* c) {  return xercesc::XMLString::replicate(c);  }
+char*    DD4hep::XML::XmlString::transcode(const XmlChar* c) {  return xercesc::XMLString::transcode(c);  }
+XmlChar* DD4hep::XML::XmlString::transcode(const char* c)    {  return xercesc::XMLString::transcode(c);  }
+void     DD4hep::XML::XmlString::release(XmlChar** p)        {  return xercesc::XMLString::release(p);    }
+void     DD4hep::XML::XmlString::release(char** p)           {  return xercesc::XMLString::release(p);    }
+
 namespace {
-  Attribute    attribute_node(XmlElement* n, const XmlChar* t)      {  return n->getAttributeNode(t);             }
-  const XmlChar* attribute_value(Attribute a)                       {  return a->getValue();                      }
-  int          node_type(XmlNode* n)                                {  return n->getNodeType();                   }
-  size_t       node_count(XmlElement* e, const XmlChar* t) {
-    XmlNodeList* l = e ? e->getElementsByTagName(t) : 0;
+  size_t       node_count(XmlElement* e, const XmlChar* t)  {
+    xercesc::DOMNodeList* l = e ? Xml(e).e->getElementsByTagName(t) : 0;
     return l ? l->getLength() : INVALID_NODE; 
   }
-  XmlElement*  node_first(XmlElement* e, const XmlChar* t) {
-    XmlNodeList* l = e ? e->getElementsByTagName(t) : 0;
-    return (XmlElement*)(l ? l->item(0) : 0);
+  XmlElement*  node_first(XmlElement* e, const XmlChar* t)  {
+    xercesc::DOMNodeList* l = e ? Xml(e).e->getElementsByTagName(t) : 0;
+    return Xml(l ? l->item(0) : 0).xe;
   }
 }
-#endif
-
-#ifndef __TIXML__
 string DD4hep::XML::_toString(const XmlChar *toTranscode)  {
   char *buff = XmlString::transcode(toTranscode);
   string tmp(buff==0 ? "" : buff);
@@ -92,6 +119,13 @@ string DD4hep::XML::_toString(const XmlChar *toTranscode)  {
 }
 #endif
 
+namespace {
+  Attribute attribute_node(XmlElement* n, const XmlChar* t) { return Attribute(_E(n)->getAttributeNode(t)); }
+  const XmlChar* attribute_value(Attribute a)               { return Xml(a).a->getValue();           }
+  int          node_type(XmlNode* n)                        { return Xml(n).n->getNodeType();        }
+  int          node_type(Handle_t n)                        { return Xml(n.ptr()).n->getNodeType();  }
+}
+
 string DD4hep::XML::_toString(Attribute attr)  {
   if ( attr ) return _toString(attribute_value(attr));
   return "";
@@ -127,25 +161,16 @@ string DD4hep::XML::_toString(double v,       const char* fmt)  { return __to_st
 int DD4hep::XML::_toInt(const XmlChar* value)  {
   if ( value )  {
     string s = _toString(value);
-    /*
-    int e;
-    errno = 0;
-    long val = ::strtol(s.c_str(),0,10);
-    e = errno;
-    if((errno == ERANGE && (val==LONG_MAX || val == LONG_MIN)) || (errno != 0 && val == 0) ) {
-    */
-      size_t idx = s.find("(int)");
-      if ( idx != string::npos ) 
-        s.erase(idx,5);
-      while(s[0]==' ')s.erase(0,1);
-      double result = eval.evaluate(s.c_str());
-      if (eval.status() != XmlTools::Evaluator::OK) {
-	cerr << s << ": ";
-	eval.print_error();
-      }
-      return (int)result;
-    //}
-    //return val;
+    size_t idx = s.find("(int)");
+    if ( idx != string::npos ) 
+      s.erase(idx,5);
+    while(s[0]==' ')s.erase(0,1);
+    double result = eval.evaluate(s.c_str());
+    if (eval.status() != XmlTools::Evaluator::OK) {
+      cerr << s << ": ";
+      eval.print_error();
+    }
+    return (int)result;
   }
   return -1;
 }
@@ -233,7 +258,7 @@ Tag_t   DD4hep::XML::operator+(const Tag_t& a,       const Strng_t& b)
 Tag_t   DD4hep::XML::operator+(const Tag_t& a,       const string& b)  
 {  return a.str() + b;                                              }
 
-#ifndef __TIXML__
+#ifndef DD4HEP_USE_TINYXML
 Strng_t DD4hep::XML::operator+(const Strng_t& a,     const XmlChar* b)
 {  return _toString(a.ptr()) + _toString(b);                      }
 
@@ -311,7 +336,7 @@ Tag_t& Tag_t::operator=(const string& s) {
 /// Copy constructor
 NodeList::NodeList(const NodeList& l)
   : m_node(l.m_node), m_ptr(0)
-#ifndef __TIXML__
+#ifndef DD4HEP_USE_TINYXML
 , m_index(0)
 #endif
 {
@@ -322,7 +347,7 @@ NodeList::NodeList(const NodeList& l)
 /// Initializing constructor
 NodeList::NodeList(XmlElement* node, const XmlChar* tag)
   : m_node(node), m_ptr(0)
-#ifndef __TIXML__
+#ifndef DD4HEP_USE_TINYXML
 , m_index(0)
 #endif
 {
@@ -337,29 +362,30 @@ NodeList::~NodeList()    {
 
 /// Reset the nodelist
 XmlElement* NodeList::reset() {
-#ifdef __TIXML__
+#ifdef DD4HEP_USE_TINYXML
   return m_ptr=node_first(m_node,m_tag);
 #else
-  m_ptr = m_node->getElementsByTagName(m_tag);
-  return (XmlElement*)m_ptr->item(m_index=0);
+  xercesc::DOMNodeList* l = Xml(m_node).e->getElementsByTagName(m_tag);
+  m_ptr = (XmlNodeList*)l;
+  return _XE(l->item(m_index=0));
 #endif
 }
 
 /// Advance to next element
 XmlElement* NodeList::next()  const {
-#ifdef __TIXML__
-  return m_ptr=(m_ptr ? m_ptr->NextSiblingElement(m_tag) : 0);
+#ifdef DD4HEP_USE_TINYXML
+  return m_ptr = _XE(m_ptr ? _E(m_ptr)->NextSiblingElement(m_tag) : 0);
 #else
-  return (XmlElement*)m_ptr->item(++m_index);
+  return _XE(_L(m_ptr)->item(++m_index));
 #endif
 }
 
 /// Go back to previous element
 XmlElement* NodeList::previous()  const {
-#ifdef __TIXML__
-  return m_ptr=(m_ptr ? m_ptr->PreviousSiblingElement(m_tag) : 0);
+#ifdef DD4HEP_USE_TINYXML
+  return m_ptr = _XE(m_ptr ? _E(m_ptr)->PreviousSiblingElement(m_tag) : 0);
 #else
-  return (XmlElement*)(m_index>0 ? m_ptr->item(--m_index) : 0);
+  return _XE(m_index>0 ? _L(m_ptr)->item(--m_index) : 0);
 #endif
 }
 
@@ -374,42 +400,30 @@ NodeList& NodeList::operator=(const NodeList& l) {
 
 /// Unicode text access to the element's tag. Tis must be wrong ....
 const XmlChar* Handle_t::rawTag() const   { 
-#ifdef __TIXML__
-  return m_node->Value();
-#else
-  return m_node->getTagName();
-#endif
+  return _E(m_node)->getTagName();
 }
 
 /// Unicode text access to the element's text
 const XmlChar* Handle_t::rawText() const   { 
-#ifdef __TIXML__
-  return m_node->GetText();
-#else
-  return m_node->getTextContent();
-#endif
+  return _E(m_node)->getTextContent();
 }
 
 /// Unicode text access to the element's value
 const XmlChar* Handle_t::rawValue() const     {
-#ifdef __TIXML__
-  return m_node->Value(); 
-#else
-  return m_node->getNodeValue();
-#endif
+  return _N(m_node)->getNodeValue();
 }
 
 /// Clone the DOMelement - with the option of a deep copy
 Handle_t Handle_t::clone(XmlDocument* new_doc) const  {
   if ( m_node ) {
-#ifdef __TIXML__
-    if ( m_node->Type() == ELEMENT_NODE_TYPE ) {
-      XmlElement* e = m_node->Clone()->ToElement();
+#ifdef DD4HEP_USE_TINYXML
+    if ( _N(m_node)->Type() == ELEMENT_NODE_TYPE ) {
+      XmlElement* e = _XE(_N(m_node)->Clone()->ToElement());
       if ( e ) return e;
     }
     throw runtime_error("TiXml: Handle_t::clone: Invalid source handle type [No element type].");
 #else
-    return (Elt_t)new_doc->importNode(m_node,true);
+    return Elt_t(_D(new_doc)->importNode(_E(m_node),true));
 #endif
   }
   throw runtime_error("Xml: Handle_t::clone: Invalid source handle.");
@@ -417,11 +431,7 @@ Handle_t Handle_t::clone(XmlDocument* new_doc) const  {
 
 /// Access the element's parent element
 Handle_t Handle_t::parent() const     {
-#ifdef __TIXML__
-  return m_node ? m_node->Parent()->ToElement() : 0;
-#else
-  return Elt_t(m_node ? m_node->getParentNode() : 0);
-#endif
+  return Elt_t(m_node ? _N(m_node)->getParentNode() : 0);
 }
 
 /// Access attribute pointer by the attribute's unicode name (no exception thrown if not present)
@@ -431,24 +441,20 @@ Attribute Handle_t::attr_nothrow(const XmlChar* tag)  const  {
 
 /// Check for the existence of a named attribute
 bool Handle_t::hasAttr(const XmlChar* tag) const    { 
-#ifdef __TIXML__
-  return m_node && 0 != m_node->Attribute(tag);
-#else
-  return m_node && 0 != m_node->getAttributeNode(tag);
-#endif
+  return m_node && 0 != _E(m_node)->getAttributeNode(tag);
 }
 
 /// Retrieve a collection of all attributes of this DOM element
 vector<Attribute> Handle_t::attributes() const {
   vector<Attribute> attrs;
   if ( m_node ) {
-#ifdef __TIXML__
-    for(TiXmlAttribute* a=m_node->FirstAttribute(); a; a=a->Next())
-      attrs.push_back(a);
+#ifdef DD4HEP_USE_TINYXML
+    for(TiXmlAttribute* a=_E(m_node)->FirstAttribute(); a; a=a->Next())
+      attrs.push_back(Attribute(a));
 #else
-    xercesc::DOMNamedNodeMap* l = m_node->getAttributes();
+    xercesc::DOMNamedNodeMap* l = _E(m_node)->getAttributes();
     for(XmlSize_t i=0, n=l->getLength(); i<n; ++i)  {
-      XmlNode* n = l->item(i);
+      xercesc::DOMNode* n = l->item(i);
       attrs.push_back(Attribute(n));
     }
 #endif
@@ -486,19 +492,15 @@ NodeList Handle_t::children(const XmlChar* tag) const {
 
 /// Append a DOM element to the current node
 void Handle_t::append(Handle_t e) const { 
-#ifdef __TIXML__
-  m_node->LinkEndChild(e.ptr());
-#else
-  m_node->appendChild(e.ptr());
-#endif
+  _N(m_node)->appendChild(_N(e.ptr()));
 }
 
 /// Remove a single child node identified by it's handle from the tree of the element
 Handle_t Handle_t::remove(Handle_t node)  const  {
-#ifdef __TIXML__
-  bool e = (m_node && node.ptr() ? m_node->RemoveChild(node.ptr()) : false); 
+#ifdef DD4HEP_USE_TINYXML
+  bool e = (m_node && node.ptr() ? _N(m_node)->RemoveChild(_N(node.ptr())) : false); 
 #else
-  Elt_t e = (Elt_t)(m_node && node.ptr() ? m_node->removeChild(node.ptr()) : 0); 
+  Elt_t e = Elt_t(m_node && node.ptr() ? _N(m_node)->removeChild(_N(node.ptr())) : 0); 
 #endif
   if ( e ) return node.ptr();
   string msg = "Handle_t::remove: ";
@@ -514,13 +516,14 @@ Handle_t Handle_t::remove(Handle_t node)  const  {
 
 /// Remove children with a given tag name from the DOM node
 void Handle_t::removeChildren(const XmlChar* tag)  const  {
-#ifdef __TIXML__
-  for(TiXmlNode* node = m_node->FirstChildElement(tag);node;m_node->FirstChildElement(tag))
-    m_node->RemoveChild(node);
+#ifdef DD4HEP_USE_TINYXML
+  for(TiXmlNode* n=_E(m_node)->FirstChildElement(tag);n;n=_E(m_node)->FirstChildElement(tag))
+    n->RemoveChild(n);
 #else
-  XmlNodeList* l=m_node->getElementsByTagName(tag);
+  xercesc::DOMElement*  e = _E(m_node);
+  xercesc::DOMNodeList* l = e->getElementsByTagName(tag);
   for(XmlSize_t i=0, n=l->getLength(); i<n; ++i)
-    m_node->removeChild(l->item(i));
+    e->removeChild(l->item(i));
 #endif
 }
 
@@ -530,68 +533,65 @@ bool Handle_t::hasChild(const XmlChar* tag) const   {
 
 /// Set the element's value
 void Handle_t::setValue(const XmlChar* text) const   {
-#ifdef __TIXML__
-  m_node->SetValue(text);
-#else
-  m_node->setNodeValue(text);
-#endif
+  _N(m_node)->setNodeValue(text);
 }
 
 /// Set the element's value
 void Handle_t::setValue(const string& text) const   {
-#ifdef __TIXML__
-  m_node->SetValue(text.c_str());
+#ifdef DD4HEP_USE_TINYXML
+  _N(m_node)->setNodeValue(text.c_str());
 #else
-  m_node->setNodeValue(Strng_t(text));
+  _N(m_node)->setNodeValue(Strng_t(text));
 #endif
 }
 
 /// Set the element's text
 void Handle_t::setText(const XmlChar* text) const   {
-#ifdef __TIXML__
-  m_node->LinkEndChild(new TiXmlText(text));
+#ifdef DD4HEP_USE_TINYXML
+  _N(m_node)->LinkEndChild(new TiXmlText(text));
 #else
-  m_node->setTextContent(text);
+  _N(m_node)->setTextContent(text);
 #endif
 }
 
 /// Set the element's text
 void Handle_t::setText(const string& text) const   {
-#ifdef __TIXML__
-  m_node->LinkEndChild(new TiXmlText(text.c_str()));
+#ifdef DD4HEP_USE_TINYXML
+  _N(m_node)->LinkEndChild(new TiXmlText(text.c_str()));
 #else
-  m_node->setTextContent(Strng_t(text));
+  _N(m_node)->setTextContent(Strng_t(text));
 #endif
 }
 
 /// Remove all attributes of this element
 void Handle_t::removeAttrs() const   {
-#ifdef __TIXML__
-  m_node->ClearAttributes();
+#ifdef DD4HEP_USE_TINYXML
+  _E(m_node)->ClearAttributes();
 #else
-  xercesc::DOMNamedNodeMap* l = m_node->getAttributes();
-  XmlSize_t i, n=l->getLength();
-  for(i=0; i<n; ++i)  {
-    XmlAttr* a = (XmlAttr*)l->item(i);
-    m_node->removeAttributeNode(a);
+  xercesc::DOMElement*      e = _E(m_node);
+  xercesc::DOMNamedNodeMap* l = e->getAttributes();
+  for(XmlSize_t i=0, n=l->getLength(); i<n; ++i)  {
+    xercesc::DOMAttr* a = (xercesc::DOMAttr*)l->item(i);
+    e->removeAttributeNode(a);
   }
 #endif
 }
 
 /// Set attributes as in argument handle
-void Handle_t::setAttrs(Handle_t e) const   {
+void Handle_t::setAttrs(Handle_t elt) const   {
   removeAttrs();
-#ifdef __TIXML__
+#ifdef DD4HEP_USE_TINYXML
+  TiXmlElement* e = Xml(elt).e;
   for(TiXmlAttribute* a=e->FirstAttribute(); a; a=a->Next())
-    m_node->SetAttribute(a->Name(),a->Value());
+    e->SetAttribute(a->Name(),a->Value());
 #else
+  xercesc::DOMElement*      e = _E(m_node);
   xercesc::DOMNamedNodeMap* l = e->getAttributes();
-  XmlSize_t i, n=l->getLength();
-  for(i=0; i<n; ++i)  {
-    XmlNode* node = l->item(i);
-    if ( node->getNodeType() == XmlNode::ATTRIBUTE_NODE ) {
-      Attribute attr = (Attribute)node;
-      m_node->setAttribute(attr->getName(),attr->getValue());
+  for(XmlSize_t i=0, len=l->getLength(); i<len; ++i)  {
+    xercesc::DOMNode* n = l->item(i);
+    if ( n->getNodeType() == xercesc::DOMNode::ATTRIBUTE_NODE ) {
+      xercesc::DOMAttr* a = (xercesc::DOMAttr*)n;
+      e->setAttribute(a->getName(),a->getValue());
     }
   }
 #endif
@@ -610,13 +610,9 @@ Attribute Handle_t::attr_ptr(const XmlChar* t)  const    {
 }
 
 /// Access attribute name (throws exception if not present)
-const XmlChar* Handle_t::attr_name(const Attribute attr)  const   {
-  if ( attr ) {
-#ifdef __TIXML__
-    return attr->Name();
-#else
-    return attr->getName();
-#endif
+const XmlChar* Handle_t::attr_name(const Attribute a)  const   {
+  if ( a ) {
+    return Xml(a).a->getName();
   }
   throw runtime_error("Attempt to access invalid XML attribute object!");
 }
@@ -670,7 +666,7 @@ Attribute Handle_t::setAttr(const XmlChar* name, const string& val)  const {
   return setAttr(name, Strng_t(val.c_str()));
 }
 
-#ifndef __TIXML__
+#ifndef DD4HEP_USE_TINYXML
 Attribute Handle_t::setAttr(const XmlChar* name, const char* v) const    {
   return setAttr(name, Strng_t(v));
 }
@@ -683,17 +679,19 @@ Attribute Handle_t::setAttr(const XmlChar* name, const Attribute v) const    {
 
 /// Generic attribute setter with unicode value
 Attribute Handle_t::setAttr(const XmlChar* name, const XmlChar* value) const  { 
-#ifdef __TIXML__
-  m_node->SetAttribute(name,value);
-  return m_node->AttributeNode(name);
+#ifdef DD4HEP_USE_TINYXML
+  TiXmlElement* e = Xml(m_node).e;
+  e->SetAttribute(name,value);
+  return Attribute(e->AttributeNode(name));
 #else
-  XmlAttr* attr = m_node->getAttributeNode(name);
-  if ( !attr ) {
-    attr = m_node->getOwnerDocument()->createAttribute(name);
-    m_node->setAttributeNode(attr);
+  xercesc::DOMElement* e = _E(m_node);
+  xercesc::DOMAttr*    a = e->getAttributeNode(name);
+  if ( !a ) {
+    a = e->getOwnerDocument()->createAttribute(name);
+    e->setAttributeNode(a);
   }
-  attr->setValue(value);
-  return attr;
+  a->setValue(value);
+  return Attribute(a);
 #endif
 }
 
@@ -745,8 +743,8 @@ static unsigned int adler32(unsigned int adler,const char* buf,size_t len)    {
 /// Checksum (sub-)tree of a xml document/tree
 unsigned int Handle_t::checksum(unsigned int param,unsigned int (fcn)(unsigned int,const XmlChar*,size_t)) const  {
   typedef std::map<std::string,std::string> StringMap;
-#ifdef __TIXML__
-  TiXmlNode* n = m_node;
+#ifdef DD4HEP_USE_TINYXML
+  TiXmlNode* n = Xml(m_node).n;
   if ( n )   {
     if ( 0 == fcn ) fcn = adler32;
     switch (n->Type())  {
@@ -773,7 +771,7 @@ unsigned int Handle_t::checksum(unsigned int param,unsigned int (fcn)(unsigned i
       break;
     }
     for(TiXmlNode* c=n->FirstChild(); c; c=c->NextSibling())
-      param = Handle_t(c->ToElement()).checksum(param,fcn);
+      param = Handle_t((XmlElement*)c->ToElement()).checksum(param,fcn);
   }
 #else
 
@@ -783,45 +781,37 @@ unsigned int Handle_t::checksum(unsigned int param,unsigned int (fcn)(unsigned i
 
 /// Create DOM element
 Handle_t Document::createElt(const XmlChar* tag)  const {
-#ifdef __TIXML__
-  return new TiXmlElement(tag);
+#ifdef DD4HEP_USE_TINYXML
+  return _XE(new TiXmlElement(tag));
 #else
-  return m_doc->createElement(tag);
+  return _XE(_D(m_doc)->createElement(tag));
 #endif
 }
 
 /// Access the ROOT eleemnt of the DOM document
 Handle_t Document::root() const  {
-#ifdef __TIXML__
-  if ( m_doc )  return m_doc->RootElement();
-#else
-  if ( m_doc )  return m_doc->getDocumentElement();
-#endif
+  if ( m_doc )  return _XE(_D(m_doc)->getDocumentElement());
   throw runtime_error("Document::root: Invalid handle!");
 }
 
 /// Standard destructor - releases the document
 DocumentHolder::~DocumentHolder()  {
-#ifdef __TIXML__
-  if (m_doc) delete m_doc;
+#ifdef DD4HEP_USE_TINYXML
+  if (m_doc) delete _D(m_doc);
 #else
-  if (m_doc) m_doc->release();
+  if (m_doc) _D(m_doc)->release();
 #endif
   m_doc = 0;
 }
 
 /// Constructor from DOM document entity
 Element::Element(const Document& document, const XmlChar* type) 
-: m_element(document.createElt(type))  
+: m_element(Xml(document.createElt(type)).xe)  
 { }
 
 /// Access the hosting document handle of this DOM element
 Document Element::document() const   {
-#ifdef __TIXML__
-  return Document(m_element ? m_element->GetDocument() : 0);
-#else
-  return Document(m_element ? m_element->getOwnerDocument() : 0);
-#endif
+  return Document((XmlDocument*)(m_element ? _N(m_element)->getOwnerDocument() : 0));
 }
 
 /// Clone the DOM element tree
@@ -891,9 +881,9 @@ void RefElement::setName(const XmlChar* new_name)  {
   setAttr(_U(name),new_name);
 }
 
-#ifndef __TIXML__
+#ifndef DD4HEP_USE_TINYXML
 Collection_t::Collection_t(Handle_t element, const XmlChar* tag) 
-  : m_children(element,tag)
+ : m_children(element,tag)
 {
   m_node = m_children.reset();
 }
@@ -924,7 +914,7 @@ void Collection_t::operator++()  const  {
   Elt_t e = this->parent();
   while(m_node)  {
     m_node = m_children.next();
-    if ( m_node && node_type(m_node) == ELEMENT_NODE_TYPE ) {
+    if ( m_node && _N(m_node)->getNodeType() == ELEMENT_NODE_TYPE ) {
       if ( this->parent() == e )
 	return;
     }
@@ -935,7 +925,7 @@ void Collection_t::operator--()  const  {
   Elt_t e = this->parent();
   while(m_node)  {
     m_node = m_children.previous();
-    if ( m_node && node_type(m_node) == ELEMENT_NODE_TYPE ) {
+    if ( m_node && _N(m_node)->getNodeType() == ELEMENT_NODE_TYPE ) {
       if ( this->parent() == e )
 	return;
     }
@@ -951,15 +941,14 @@ void Collection_t::operator--(int)  const  {
 }
 
 Handle_t Document::clone(Handle_t source) const  {
-#ifdef __TIXML__
-  return (XmlElement*)source.clone(0);
+#ifdef DD4HEP_USE_TINYXML
+  return _XE(source.clone(0));
 #else
-  
-  return (XmlElement*)(m_doc->importNode(source.ptr(),true));
+  return _XE(_D(m_doc)->importNode(_E(source.ptr()),true));
 #endif
 }
 
-#ifdef __TIXML__
+#ifdef DD4HEP_USE_TINYXML
 #include "tinyxml_inl.h"
 #include "tinyxmlerror_inl.h"
 #include "tinyxmlparser_inl.h"
diff --git a/DDCore/src/plugins/LCDDConverter.cpp b/DDCore/src/plugins/LCDDConverter.cpp
index 188eaa8f0562c256f71dcb169d369d477d5992bd..a4f7a877bb15cb4607b54b764797f1727cb8d0c7 100644
--- a/DDCore/src/plugins/LCDDConverter.cpp
+++ b/DDCore/src/plugins/LCDDConverter.cpp
@@ -839,8 +839,12 @@ template <typename O, typename C, typename F> void handleRMap(const O* o, const
 /// Create geometry conversion
 xml_doc_t LCDDConverter::createGDML(DetElement top) {
   LCDD& lcdd = m_lcdd;
+  if ( !top.isValid() ) {
+    throw runtime_error("Attempt to call createGDML with an invalid geometry!");
+  }
   GeometryInfo& geo = *(m_dataPtr=new GeometryInfo);
   m_data->clear();
+
   collect(top,geo);
   m_checkOverlaps = false;
 
@@ -900,9 +904,14 @@ xml_doc_t LCDDConverter::createGDML(DetElement top) {
   return geo.doc;
 }
 
+
 /// Create geometry conversion
 xml_doc_t LCDDConverter::createLCDD(DetElement top) {
   LCDD& lcdd = m_lcdd;
+  if ( !top.isValid() ) {
+    throw runtime_error("Attempt to call createLCDD with an invalid geometry!");
+  }
+
   GeometryInfo& geo = *(m_dataPtr=new GeometryInfo);
   m_data->clear();
   collect(top,geo);
diff --git a/DDCore/src/plugins/LCDDConverter.h b/DDCore/src/plugins/LCDDConverter.h
index 1bd708e5ade1f627d49020d0983a3e60e999f3bf..ef72f9c1bd1cf00b5b304d40733ef49e8b6f4bb8 100644
--- a/DDCore/src/plugins/LCDDConverter.h
+++ b/DDCore/src/plugins/LCDDConverter.h
@@ -33,7 +33,7 @@ class TGeoMatrix;
 namespace DD4hep {
 
   /*
-   *   XML namespace declaration
+   *   Geomentry namespace declaration
    */
   namespace Geometry   {
 
diff --git a/DDExamples/AlignDet/CMakeLists.txt b/DDExamples/AlignDet/CMakeLists.txt
index 91fc6a7eb10a13652b67aacefd3b0db36ea92de7..f9283f578f78699f9f27335636fd35fab811c845 100644
--- a/DDExamples/AlignDet/CMakeLists.txt
+++ b/DDExamples/AlignDet/CMakeLists.txt
@@ -3,12 +3,10 @@ cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
 
 include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include 
                      ${CMAKE_SOURCE_DIR}/DDCore/include 
-                     ${ROOT_INCLUDE_DIR}
-                     ${XERCESC_INCLUDE_DIR})
+                     ${ROOT_INCLUDE_DIR})
 
-if(DD4HEP_USE_XERCESC)
-  file(GLOB sources src/*.cpp)
-endif()
+include(DD4hep_XML_setup)
+file(GLOB sources src/*.cpp)
 
 add_executable(Aligntest test/main.cpp ${sources})
 target_link_libraries(Aligntest DD4hepCore ${ROOT_LIBRARIES} Rint Reflex)
diff --git a/DDExamples/CLICSiD/CMakeLists.txt b/DDExamples/CLICSiD/CMakeLists.txt
index 2dcaa5af1fae4353ece89b58faaa6bb30d9c6349..7095c6a737ce94083587a722635e48548c11045e 100644
--- a/DDExamples/CLICSiD/CMakeLists.txt
+++ b/DDExamples/CLICSiD/CMakeLists.txt
@@ -2,15 +2,11 @@ cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
 
 include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include 
                      ${CMAKE_SOURCE_DIR}/DDCore/include 
-                     ${ROOT_INCLUDE_DIR}
-                     ${XERCESC_INCLUDE_DIR})
+                     ${ROOT_INCLUDE_DIR})
 
 file(GLOB sources src/*.cpp)
-
-if(DD4HEP_USE_XERCESC)
-  add_definitions(-DDD4HEP_USE_XERCESC)
-endif()
+include(DD4hep_XML_setup)
 
 add_library(CLICSiD SHARED ${sources})
-target_link_libraries(CLICSiD DD4hepCore ${ROOT_LIBRARIES} ${XERCESC_LIBRARIES})
+target_link_libraries(CLICSiD DD4hepCore ${ROOT_LIBRARIES})
 dd4hep_generate_rootmap(CLICSiD)
diff --git a/DDExamples/CLICSiDSimu/CMakeLists.txt b/DDExamples/CLICSiDSimu/CMakeLists.txt
index daf48f561d015c175cb5ece0ec1cb9132b032838..0048b1163b340d65df17ce6eeb584137fac81028 100644
--- a/DDExamples/CLICSiDSimu/CMakeLists.txt
+++ b/DDExamples/CLICSiDSimu/CMakeLists.txt
@@ -13,16 +13,13 @@ if(Geant4_gdml_FOUND)
   add_definitions(-DGEANT4_HAS_GDML)
 endif()
 
-if(DD4HEP_USE_XERCESC)
-  add_definitions(-DDD4HEP_USE_XERCESC)
-  set(libraries CLICSiD ${XERCESC_LIBRARIES})
-endif()
+include(DD4hep_XML_setup)
+set(libraries CLICSiD ${XML_LIBRARIES})
 
 include_directories( ${CMAKE_SOURCE_DIR}/DDCore/include
                      ${CMAKE_SOURCE_DIR}/DDG4/include
                      ${CMAKE_CURRENT_SOURCE_DIR}/include
                      ${ROOT_INCLUDE_DIR}
-                     ${XERCESC_INCLUDE_DIR}
                      ${Geant4_INCLUDE_DIRS})
 
 file(GLOB sources src/*.cpp)
diff --git a/DDExamples/ILDExDet/CMakeLists.txt b/DDExamples/ILDExDet/CMakeLists.txt
index 050318cd7820b6372ddd068a75ed111785b91807..fedc2f86083d26b6ad8a2d562692af0a283cb146 100644
--- a/DDExamples/ILDExDet/CMakeLists.txt
+++ b/DDExamples/ILDExDet/CMakeLists.txt
@@ -4,14 +4,10 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include
                      ${CMAKE_SOURCE_DIR}/DDCore/include 
                      ${ROOT_INCLUDE_DIR})
 
-file(GLOB sources src/*.cpp)
+file(GLOB sources src/*.cpp src/compact/*.cpp)
 file(GLOB headers include/*.h)
 
-if(DD4HEP_USE_XERCESC)
-  file(GLOB xmlsources src/compact/*.cpp)
-  list(APPEND sources ${xmlsources})
-  include_directories(${XERCESC_INCLUDE_DIR})
-endif()
+include(DD4hep_XML_setup)
 
 if(DD4HEP_USE_PYROOT)
   ROOT_GENERATE_DICTIONARY(G__ILDEx ${headers} LINKDEF include/ROOT/LinkDef.h)
@@ -22,5 +18,5 @@ endif()
 
 add_library(ILDEx SHARED ${sources})
 target_link_libraries(ILDEx DD4hepCore)
+#---Rootmap generation--------------------------------------------------------------
 dd4hep_generate_rootmap(ILDEx)
-
diff --git a/DDG4/CMakeLists.txt b/DDG4/CMakeLists.txt
index c63ef1d0699f9d32f74a8b15e473e395d711cf49..35ea94cac658cd9a29c97b93967d409a0bab6058 100644
--- a/DDG4/CMakeLists.txt
+++ b/DDG4/CMakeLists.txt
@@ -6,17 +6,14 @@ if(NOT Geant4_clhep_FOUND)
   set(Geant4_LIBRARIES ${Geant4_LIBRARIES} ${CLHEP_LIBRARIES})
 endif()
 
-if(DD4HEP_USE_XERCESC)
-  add_definitions(-DDD4HEP_USE_XERCESC)
-endif()
+include(DD4hep_XML_setup)
 
 #---Includedirs-------------------------------------------------------------------
 include_directories(${CMAKE_SOURCE_DIR}/DDCore/include
                     ${CMAKE_CURRENT_SOURCE_DIR}/include 
                     ${ROOT_INCLUDE_DIR}
                     ${CLHEP_INCLUDE_DIR}
-                    ${Geant4_INCLUDE_DIRS}
-                    ${XERCESC_INCLUDE_DIR})
+                    ${Geant4_INCLUDE_DIRS})
 
 #---Add Library-------------------------------------------------------------------
 file(GLOB sources src/*.cpp)
@@ -25,5 +22,4 @@ if(NOT DD4HEP_USE_XERCESC)
 endif()
 add_library(DD4hepG4 SHARED ${sources})
 target_link_libraries(DD4hepG4 DD4hepCore ${ROOT_LIBRARIES} Reflex ${Geant4_LIBRARIES})
-#target_link_libraries(DD4hepG4 DD4hepCore ${ROOT_LIBRARIES} ${XERCESC_LIBRARIES} ${Geant4_LIBRARIES})
 dd4hep_generate_rootmap(DD4hepG4)
diff --git a/cmake/DD4hep.cmake b/cmake/DD4hep.cmake
index 52b139e052ac45b5f0968f90765ee9f6eb17adbb..d013076ba3675564f4afe1f9d40966ace44916f2 100644
--- a/cmake/DD4hep.cmake
+++ b/cmake/DD4hep.cmake
@@ -17,6 +17,7 @@ function(dd4hep_generate_rootmap library)
   #gaudi_merge_files_append(Rootmap ${library}Rootmap ${CMAKE_CURRENT_BINARY_DIR}/${library}.rootmap)
 endfunction()
 
+
 #---------------------------------------------------------------------------------------------------
 # dd4hep_install_library(library)
 #
diff --git a/cmake/DD4hep_XML_setup.cmake b/cmake/DD4hep_XML_setup.cmake
new file mode 100644
index 0000000000000000000000000000000000000000..597e4ddba08ee92af5796088eee94e51d53d0159
--- /dev/null
+++ b/cmake/DD4hep_XML_setup.cmake
@@ -0,0 +1,8 @@
+if(DD4HEP_USE_XERCESC)
+  add_definitions(-DDD4HEP_USE_XERCESC)
+  include_directories(${XERCESC_INCLUDE_DIR})
+  set(XML_LIBRARIES ${XERCESC_LIBRARIES})
+else()
+  add_definitions(-DDD4HEP_USE_TINYXML)
+  set(XML_LIBRARIES)
+endif()