Commits

Anonymous committed 316fc9b

applied most of a cleanup patch by Nick Wellnhofer that removes setting of global variables

Comments (0)

Files changed (4)

     /* calling xmlInitParser() here is definitly wrong!  */
     /* xmlInitParser(); */ 
 
+#ifndef WITH_SERRORS
     xmlGetWarningsDefaultValue = 0;
-
+#endif
     if ( self != NULL ) {
         /* first fetch the values from the hash */
         real_obj = (HV *)SvRV(self);
         item =  hv_fetch( real_obj, "XML_LIBXML_LINENUMBERS", 22, 0 );
         if ( item != NULL && SvTRUE(*item) ) {
             if (ctxt) ctxt->linenumbers = 1;
-            else xmlLineNumbersDefault( 1 );
         }
         else {
             if (ctxt) ctxt->linenumbers = 0;
-            else xmlLineNumbersDefault( 0 );
         }
 
         item = hv_fetch(real_obj, "ext_ent_handler", 15, 0);
 
 void
 LibXML_cleanup_parser() {
-    xmlSubstituteEntitiesDefaultValue = 1;
-    xmlKeepBlanksDefaultValue = 1;
+#ifndef WITH_SERRORS
     xmlGetWarningsDefaultValue = 0;
-    xmlLoadExtDtdDefaultValue = 5;
-    xmlPedanticParserDefaultValue = 0;
-    xmlLineNumbersDefault( 0 );
-    xmlDoValidityCheckingDefaultValue = 0;
-
+#endif
     if (LibXML_old_ext_ent_loader != NULL ) {
         xmlSetExternalEntityLoader( (xmlExternalEntityLoader)LibXML_old_ext_ent_loader );
     }
     LIBXML_TEST_VERSION
     xmlInitParser();
     PmmSAXInitialize(aTHX);
-
-    xmlSetGenericErrorFunc( NULL ,
-                           (xmlGenericErrorFunc)LibXML_error_handler_ctx);
-    xmlDoValidityCheckingDefaultValue = 0;
-    xmlSubstituteEntitiesDefaultValue = 1;
+#ifndef WITH_SERRORS
     xmlGetWarningsDefaultValue = 0;
-    xmlKeepBlanksDefaultValue = 1;
-    xmlLoadExtDtdDefaultValue = 5;
-    xmlPedanticParserDefaultValue = 0;
-    xmlLineNumbersDefault(0);
-    xmlSetGenericErrorFunc(NULL, NULL);
+#endif
 #ifdef LIBXML_CATALOG_ENABLED
     /* xmlCatalogSetDebug(10); */
     xmlInitializeCatalog(); /* use catalog data */
         HV * real_obj;
         int well_formed;
         int valid;
+        int validate;
         xmlDocPtr real_doc;
         int recover = 0;
 	PREINIT_SAVED_ERROR
             xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt((const char*)ptr, len);
             if (ctxt == NULL) {
 	        CLEANUP_ERROR_HANDLER;
-                REPORT_ERROR(recover ? recover : 1);
+                REPORT_ERROR(1);
                 croak("Could not create memory parser context!\n");
             }
             xs_warn( "context created\n");
 
             xs_warn( "context initialized\n" );
 
-            {
-                /* TODO: make this into a macro: */
-                xmlParseDocument(ctxt);
-                xs_warn( "document parsed \n");
-            }
+            xmlParseDocument(ctxt);
+            xs_warn( "document parsed \n");
 
             ctxt->directory = NULL;
             well_formed = ctxt->wellFormed;
             valid = ctxt->valid;
+            validate = ctxt->validate;
             real_doc = ctxt->myDoc;
             ctxt->myDoc = NULL;
             xmlFreeParserCtxt(ctxt);
             }
             if ( ! LibXML_will_die_ctx(saved_error, recover) &&
 		 (recover || ( well_formed &&
-                              ( !xmlDoValidityCheckingDefaultValue
+                              ( !validate
                                 || ( valid || ( real_doc->intSubset == NULL
                                                 && real_doc->extSubset == NULL )))))) {
                 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
         HV * real_obj;
         int well_formed;
         int valid;
+        int validate;
         xmlDocPtr real_doc;
         int recover = 0;
         PREINIT_SAVED_ERROR
             ctxt = xmlCreatePushParserCtxt(NULL, NULL, buffer, read_length, NULL);
             if (ctxt == NULL) {
                 CLEANUP_ERROR_HANDLER;
-                REPORT_ERROR(recover ? recover : 1);
+                REPORT_ERROR(1);
                 croak("Could not create xml push parser context!\n");
             }
             xs_warn( "context created\n");
             ctxt->directory = NULL;
             well_formed = ctxt->wellFormed;
             valid = ctxt->valid;
+            validate = ctxt->validate;
             real_doc = ctxt->myDoc;
             ctxt->myDoc = NULL;
             xmlFreeParserCtxt(ctxt);
             }
 
             if ( recover || ( well_formed &&
-                              ( !xmlDoValidityCheckingDefaultValue
+                              ( !validate
                                 || ( valid || ( real_doc->intSubset == NULL
                                                 && real_doc->extSubset == NULL ))))) {
                 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
         HV * real_obj;
         int well_formed;
         int valid;
+        int validate;
         xmlDocPtr real_doc;
         int recover = 0;
         PREINIT_SAVED_ERROR
             xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(filename);
             if (ctxt == NULL) {
                 CLEANUP_ERROR_HANDLER;
-                REPORT_ERROR(recover ? recover : 1);
+                REPORT_ERROR(1);
                 croak("Could not create file parser context for file \"%s\": %s\n",
                       filename, strerror(errno));
             }
             ctxt->_private = (void*)self;
 
             xs_warn( "context initialized\n" );
-            {
-                xmlParseDocument(ctxt);
-                xs_warn( "document parsed \n");
-            }
+            xmlParseDocument(ctxt);
+            xs_warn( "document parsed \n");
 
             well_formed = ctxt->wellFormed;
             valid = ctxt->valid;
+            validate = ctxt->validate;
             real_doc = ctxt->myDoc;
             ctxt->myDoc = NULL;
             xmlFreeParserCtxt(ctxt);
         }
 
         if ( real_doc != NULL ) {
-
             if ( recover || ( well_formed &&
-                              ( !xmlDoValidityCheckingDefaultValue
+                              ( !validate
                                 || ( valid || ( real_doc->intSubset == NULL
                                                 && real_doc->extSubset == NULL ))))) {
                 RETVAL = LibXML_NodeToSv( real_obj, INT2PTR(xmlNodePtr,real_doc) );
       </para>
       <variablelist>
 	<varlistentry>
+	  <term>$XML::LibXML::Error::WARNINGS</term>
+	  <listitem>
+	    <funcsynopsis>
+	      <funcsynopsisinfo>$XML::LibXML::Error::WARNINGS=1;</funcsynopsisinfo>
+	    </funcsynopsis>
+	    <para>Traditionally, XML::LibXML was supressing parser
+	      warnings by setting libxml2's global variable
+	      xmlGetWarningsDefaultValue to 0. Since 
+	      1.70 we do not change libxml2's global
+	      variables anymore; for backward compatibility,
+	      XML::LibXML suppresses warnings.
+	      This variable can be set to 1
+	      to enable reporting of these warnings via
+	      Perl <literal>warn</literal>
+	      and to 2 to report hem via <literal>die</literal>.
+	    </para>
+	  </listitem>
 	  <term>as_string</term>
 	  <listitem>
 	    <funcsynopsis>

lib/XML/LibXML/Error.pm

 package XML::LibXML::Error;
 
 use strict;
-use vars qw($AUTOLOAD @error_domains $VERSION);
+use vars qw($AUTOLOAD @error_domains $VERSION $WARNINGS);
 use Carp;
 use overload 
   '""' => \&as_string,
   },
   fallback => 1;
 
-
+$WARNINGS = 0; # 0: supress, 1: report via warn, 2: report via die
 $VERSION = "1.70"; # VERSION TEMPLATE: DO NOT CHANGE
 
 use constant XML_ERR_NONE	     => 0;
       my ($xE,$prev) = @_;
       my $terr;
       $terr=XML::LibXML::Error->new($xE);
+      if ($terr->{level} == XML_ERR_WARNING and $WARNINGS!=2) {
+	warn $terr if $WARNINGS;
+	return $prev;
+      }
       #unless ( defined $terr->{file} and length $terr->{file} ) {
 	# this would make it easier to recognize parsed strings
 	# but it breaks old implementations
 <n2:pdu xmlns:n1="http://example.com"
            xmlns:n2="http://foo.example"
            xml:lang="fr"
-           xml:space="retain">
+           xml:space="preserve">
   <n1:elem2 xmlns:n1="http://example.net" xml:lang="en">
      <n3:stuff xmlns:n3="ftp://example.org"/>
   </n1:elem2>