diff -ur XML-LibXML-1.70/LibXML.pm XML-LibXML-1.70-v1/LibXML.pm
--- XML-LibXML-1.70/LibXML.pm	2009-10-04 23:20:32.000000000 +0200
+++ XML-LibXML-1.70-new/LibXML.pm	2011-05-15 16:49:24.463604922 +0200
@@ -441,6 +441,12 @@
 # callback functions                                                      #
 #-------------------------------------------------------------------------#
 
+use Data::Dumper;
+sub externalEntityLoader(&)
+{
+	return _externalEntityLoader($_[0]);
+}
+
 sub input_callbacks {
     my $self     = shift;
     my $icbclass = shift;
diff -ur XML-LibXML-1.70/LibXML.xs XML-LibXML-1.70-v1/LibXML.xs
--- XML-LibXML-1.70/LibXML.xs	2009-10-07 00:02:23.000000000 +0200
+++ XML-LibXML-1.70-v1/LibXML.xs	2011-05-18 22:40:35.374150865 +0200
@@ -146,6 +146,9 @@
 /* this should keep the default */
 static xmlExternalEntityLoader LibXML_old_ext_ent_loader = NULL;
 
+/* global external entity loader */
+SV *EXTERNAL_ENTITY_LOADER_FUNC = (SV *)NULL;
+
 SV* PROXY_NODE_REGISTRY_MUTEX = NULL;
 
 /* ****************************************************************
@@ -778,8 +781,7 @@
         const char * ID,
         xmlParserCtxtPtr ctxt)
 {
-    SV * self;
-    HV * real_obj;
+
     SV ** func;
     int count;
     SV * results;
@@ -787,7 +789,8 @@
     const char * results_pv;
     xmlParserInputBufferPtr input_buf;
 
-    if (ctxt->_private == NULL) {
+    if (ctxt->_private == NULL
+    	&& EXTERNAL_ENTITY_LOADER_FUNC == NULL) {
         return xmlNewInputFromFile(ctxt, URL);
     }
 
@@ -798,11 +801,22 @@
         ID = "";
     }
 
-    self = (SV *)ctxt->_private;
-    real_obj = (HV *)SvRV(self);
-    func = hv_fetch(real_obj, "ext_ent_handler", 15, 0);
+    /* fetch entity loader function */
+    if(EXTERNAL_ENTITY_LOADER_FUNC != NULL)
+    {
+    	func = &EXTERNAL_ENTITY_LOADER_FUNC;
+    }
+    else
+    {
+        SV * self;
+	HV * real_obj;
+    
+	self = (SV *)ctxt->_private;
+	real_obj = (HV *)SvRV(self);
+	func = hv_fetch(real_obj, "ext_ent_handler", 15, 0);
+    }
 
-    if (func != NULL  && SvTRUE(*func)) {
+    if (func != NULL && SvTRUE(*func)) {
         dTHX;
         dSP;
 
@@ -899,18 +913,21 @@
             if (ctxt) ctxt->linenumbers = 0;
         }
 
-        item = hv_fetch(real_obj, "ext_ent_handler", 15, 0);
-        if ( item != NULL  && SvTRUE(*item)) {
-            LibXML_old_ext_ent_loader =  xmlGetExternalEntityLoader();
-            xmlSetExternalEntityLoader( (xmlExternalEntityLoader)LibXML_load_external_entity );
-        }
-        else {
-            if (parserOptions & XML_PARSE_NONET) {
-                LibXML_old_ext_ent_loader =  xmlGetExternalEntityLoader();
-                xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
-            }
-            /* LibXML_old_ext_ent_loader =  NULL; */
-        }
+	if(LibXML_old_ext_ent_loader == NULL)
+	{
+	        item = hv_fetch(real_obj, "ext_ent_handler", 15, 0);
+	        if (item != NULL  && SvTRUE(*item)) {
+	            LibXML_old_ext_ent_loader =  xmlGetExternalEntityLoader();
+	            xmlSetExternalEntityLoader( (xmlExternalEntityLoader)LibXML_load_external_entity );
+	        }
+	        else {
+	            if (parserOptions & XML_PARSE_NONET) {
+	                LibXML_old_ext_ent_loader =  xmlGetExternalEntityLoader();
+	                xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
+	            }
+	            /* LibXML_old_ext_ent_loader =  NULL; */
+	        }
+	}
     }
 
     return real_obj;
@@ -921,7 +938,8 @@
 #ifndef WITH_SERRORS
     xmlGetWarningsDefaultValue = 0;
 #endif
-    if (LibXML_old_ext_ent_loader != NULL ) {
+    if (EXTERNAL_ENTITY_LOADER_FUNC == NULL
+    		&& LibXML_old_ext_ent_loader != NULL) {
         xmlSetExternalEntityLoader( (xmlExternalEntityLoader)LibXML_old_ext_ent_loader );
     }
 }
@@ -2642,6 +2660,27 @@
     OUTPUT:
         RETVAL
 
+SV*
+_externalEntityLoader( loader )
+	SV* loader
+    CODE:
+	{
+		RETVAL = EXTERNAL_ENTITY_LOADER_FUNC;
+		if(EXTERNAL_ENTITY_LOADER_FUNC == NULL)
+			EXTERNAL_ENTITY_LOADER_FUNC = newSVsv(loader);
+/*
+		else
+			SvSetSv(EXTERNAL_ENTITY_LOADER_FUNC, loader);
+*/
+		
+		if (LibXML_old_ext_ent_loader == NULL ) {
+			LibXML_old_ext_ent_loader = xmlGetExternalEntityLoader();
+			xmlSetExternalEntityLoader((xmlExternalEntityLoader)LibXML_load_external_entity);
+		}
+	}
+    OUTPUT:
+    	RETVAL
+
 MODULE = XML::LibXML         PACKAGE = XML::LibXML::HashTable
 
 xmlHashTablePtr
@@ -9386,4 +9425,3 @@
 #endif
     OUTPUT:
         RETVAL
-
