--- include/libxml/parser.h
+++ include/libxml/parser.h
@@ -592,7 +592,7 @@
  * Display and format a warning messages, callback.
  */
 typedef void (XMLCDECL *warningSAXFunc) (void *ctx,
-				const char *msg, ...);
+				const char *msg, ...) ATTRIBUTE_PRINTF(2,3);
 /**
  * errorSAXFunc:
  * @ctx:  an XML parser context
@@ -602,7 +602,7 @@
  * Display and format an error messages, callback.
  */
 typedef void (XMLCDECL *errorSAXFunc) (void *ctx,
-				const char *msg, ...);
+				const char *msg, ...) ATTRIBUTE_PRINTF(2,3);
 /**
  * fatalErrorSAXFunc:
  * @ctx:  an XML parser context
@@ -614,7 +614,7 @@
  *       get all the callbacks for errors.
  */
 typedef void (XMLCDECL *fatalErrorSAXFunc) (void *ctx,
-				const char *msg, ...);
+				const char *msg, ...) ATTRIBUTE_PRINTF(2,3);
 /**
  * isStandaloneSAXFunc:
  * @ctx:  the user data (XML parser context)
--- include/libxml/relaxng.h
+++ include/libxml/relaxng.h
@@ -27,8 +27,8 @@
 /**
  * A schemas validation context
  */
-typedef void (XMLCDECL *xmlRelaxNGValidityErrorFunc) (void *ctx, const char *msg, ...);
-typedef void (XMLCDECL *xmlRelaxNGValidityWarningFunc) (void *ctx, const char *msg, ...);
+typedef void (XMLCDECL *xmlRelaxNGValidityErrorFunc) (void *ctx, const char *msg, ...) ATTRIBUTE_PRINTF(2,3);
+typedef void (XMLCDECL *xmlRelaxNGValidityWarningFunc) (void *ctx, const char *msg, ...) ATTRIBUTE_PRINTF(2,3);
 
 typedef struct _xmlRelaxNGParserCtxt xmlRelaxNGParserCtxt;
 typedef xmlRelaxNGParserCtxt *xmlRelaxNGParserCtxtPtr;
--- include/libxml/valid.h
+++ include/libxml/valid.h
@@ -41,7 +41,7 @@
  */
 typedef void (XMLCDECL *xmlValidityErrorFunc) (void *ctx,
 			     const char *msg,
-			     ...);
+			     ...) ATTRIBUTE_PRINTF(2,3);
 
 /**
  * xmlValidityWarningFunc:
@@ -56,7 +56,7 @@
  */
 typedef void (XMLCDECL *xmlValidityWarningFunc) (void *ctx,
 			       const char *msg,
-			       ...);
+			       ...) ATTRIBUTE_PRINTF(2,3);
 
 #ifdef IN_LIBXML
 /**
--- include/libxml/xmlerror.h
+++ include/libxml/xmlerror.h
@@ -829,7 +829,7 @@
  */
 typedef void (XMLCDECL *xmlGenericErrorFunc) (void *ctx,
 				 const char *msg,
-	 			 ...);
+	 			 ...) ATTRIBUTE_PRINTF(2,3);
 /**
  * xmlStructuredErrorFunc:
  * @userData:  user provided data for the error callback
@@ -860,19 +860,19 @@
 XMLPUBFUN void XMLCDECL	
     xmlParserError		(void *ctx,
 				 const char *msg,
-				 ...);
+				 ...) ATTRIBUTE_PRINTF(2,3);
 XMLPUBFUN void XMLCDECL	
     xmlParserWarning		(void *ctx,
 				 const char *msg,
-				 ...);
+				 ...) ATTRIBUTE_PRINTF(2,3);
 XMLPUBFUN void XMLCDECL	
     xmlParserValidityError	(void *ctx,
 				 const char *msg,
-				 ...);
+				 ...) ATTRIBUTE_PRINTF(2,3);
 XMLPUBFUN void XMLCDECL	
     xmlParserValidityWarning	(void *ctx,
 				 const char *msg,
-				 ...);
+				 ...) ATTRIBUTE_PRINTF(2,3);
 XMLPUBFUN void XMLCALL	
     xmlParserPrintFileInfo	(xmlParserInputPtr input);
 XMLPUBFUN void XMLCALL	
@@ -916,7 +916,7 @@
 				 int int1,
 				 int col,
 				 const char *msg,
-				 ...);
+				 ...) ATTRIBUTE_PRINTF(16,17);
 XMLPUBFUN void XMLCALL 
     __xmlSimpleError		(int domain,
     				 int code,
--- include/libxml/xmlschemas.h
+++ include/libxml/xmlschemas.h
@@ -87,8 +87,8 @@
 /**
  * A schemas validation context
  */
-typedef void (XMLCDECL *xmlSchemaValidityErrorFunc) (void *ctx, const char *msg, ...);
-typedef void (XMLCDECL *xmlSchemaValidityWarningFunc) (void *ctx, const char *msg, ...);
+typedef void (XMLCDECL *xmlSchemaValidityErrorFunc) (void *ctx, const char *msg, ...) ATTRIBUTE_PRINTF(2,3);
+typedef void (XMLCDECL *xmlSchemaValidityWarningFunc) (void *ctx, const char *msg, ...) ATTRIBUTE_PRINTF(2,3);
 
 typedef struct _xmlSchemaParserCtxt xmlSchemaParserCtxt;
 typedef xmlSchemaParserCtxt *xmlSchemaParserCtxtPtr;
--- include/libxml/xmlversion.h.in
+++ include/libxml/xmlversion.h.in
@@ -384,8 +384,12 @@
 #ifndef ATTRIBUTE_UNUSED
 #define ATTRIBUTE_UNUSED __attribute__((unused))
 #endif
+#ifndef ATTRIBUTE_PRINTF
+#define ATTRIBUTE_PRINTF(fmt,args) __attribute__((__format__(__printf__,fmt,args)))
+#endif
 #else
 #define ATTRIBUTE_UNUSED
+#define ATTRIBUTE_PRINTF
 #endif
 
 #ifdef __cplusplus
--- include/libxml/xmlwriter.h
+++ include/libxml/xmlwriter.h
@@ -69,11 +69,13 @@
     XMLPUBFUN int XMLCALL xmlTextWriterEndComment(xmlTextWriterPtr writer);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteFormatComment(xmlTextWriterPtr writer,
-                                        const char *format, ...);
+                                        const char *format, ...)
+					ATTRIBUTE_PRINTF(2,3);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatComment(xmlTextWriterPtr writer,
                                          const char *format,
-                                         va_list argptr);
+                                         va_list argptr)
+					 ATTRIBUTE_PRINTF(2,0);
     XMLPUBFUN int XMLCALL xmlTextWriterWriteComment(xmlTextWriterPtr
                                                     writer,
                                                     const xmlChar *
@@ -102,12 +104,14 @@
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteFormatElement(xmlTextWriterPtr writer,
                                         const xmlChar * name,
-                                        const char *format, ...);
+                                        const char *format, ...)
+					ATTRIBUTE_PRINTF(3,4);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatElement(xmlTextWriterPtr writer,
                                          const xmlChar * name,
                                          const char *format,
-                                         va_list argptr);
+                                         va_list argptr)
+					 ATTRIBUTE_PRINTF(3,0);
     XMLPUBFUN int XMLCALL xmlTextWriterWriteElement(xmlTextWriterPtr
                                                     writer,
                                                     const xmlChar * name,
@@ -118,14 +122,16 @@
                                           const xmlChar * prefix,
                                           const xmlChar * name,
                                           const xmlChar * namespaceURI,
-                                          const char *format, ...);
+                                          const char *format, ...)
+					  ATTRIBUTE_PRINTF(5,6);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatElementNS(xmlTextWriterPtr writer,
                                            const xmlChar * prefix,
                                            const xmlChar * name,
                                            const xmlChar * namespaceURI,
                                            const char *format,
-                                           va_list argptr);
+                                           va_list argptr)
+					   ATTRIBUTE_PRINTF(5,0);
     XMLPUBFUN int XMLCALL xmlTextWriterWriteElementNS(xmlTextWriterPtr
                                                       writer,
                                                       const xmlChar *
@@ -141,10 +147,12 @@
  */
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteFormatRaw(xmlTextWriterPtr writer,
-                                    const char *format, ...);
+                                    const char *format, ...)
+				    ATTRIBUTE_PRINTF(2,3);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatRaw(xmlTextWriterPtr writer,
-                                     const char *format, va_list argptr);
+                                     const char *format, va_list argptr)
+				     ATTRIBUTE_PRINTF(2,0);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteRawLen(xmlTextWriterPtr writer,
                                  const xmlChar * content, int len);
@@ -154,12 +162,14 @@
     XMLPUBFUN int XMLCALL xmlTextWriterWriteFormatString(xmlTextWriterPtr
                                                          writer,
                                                          const char
-                                                         *format, ...);
+                                                         *format, ...)
+							 ATTRIBUTE_PRINTF(2,3);
     XMLPUBFUN int XMLCALL xmlTextWriterWriteVFormatString(xmlTextWriterPtr
                                                           writer,
                                                           const char
                                                           *format,
-                                                          va_list argptr);
+                                                          va_list argptr)
+							  ATTRIBUTE_PRINTF(2,0);
     XMLPUBFUN int XMLCALL xmlTextWriterWriteString(xmlTextWriterPtr writer,
                                                    const xmlChar *
                                                    content);
@@ -193,12 +203,14 @@
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteFormatAttribute(xmlTextWriterPtr writer,
                                           const xmlChar * name,
-                                          const char *format, ...);
+                                          const char *format, ...)
+					  ATTRIBUTE_PRINTF(3,4);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatAttribute(xmlTextWriterPtr writer,
                                            const xmlChar * name,
                                            const char *format,
-                                           va_list argptr);
+                                           va_list argptr)
+					   ATTRIBUTE_PRINTF(3,0);
     XMLPUBFUN int XMLCALL xmlTextWriterWriteAttribute(xmlTextWriterPtr
                                                       writer,
                                                       const xmlChar * name,
@@ -209,14 +221,16 @@
                                             const xmlChar * prefix,
                                             const xmlChar * name,
                                             const xmlChar * namespaceURI,
-                                            const char *format, ...);
+                                            const char *format, ...)
+					    ATTRIBUTE_PRINTF(5,6);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatAttributeNS(xmlTextWriterPtr writer,
                                              const xmlChar * prefix,
                                              const xmlChar * name,
                                              const xmlChar * namespaceURI,
                                              const char *format,
-                                             va_list argptr);
+                                             va_list argptr)
+					     ATTRIBUTE_PRINTF(5,0);
     XMLPUBFUN int XMLCALL xmlTextWriterWriteAttributeNS(xmlTextWriterPtr
                                                         writer,
                                                         const xmlChar *
@@ -242,11 +256,13 @@
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteFormatPI(xmlTextWriterPtr writer,
                                    const xmlChar * target,
-                                   const char *format, ...);
+                                   const char *format, ...)
+				   ATTRIBUTE_PRINTF(3,4);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatPI(xmlTextWriterPtr writer,
                                     const xmlChar * target,
-                                    const char *format, va_list argptr);
+                                    const char *format, va_list argptr)
+				    ATTRIBUTE_PRINTF(3,0);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWritePI(xmlTextWriterPtr writer,
                              const xmlChar * target,
@@ -270,10 +286,12 @@
  */
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteFormatCDATA(xmlTextWriterPtr writer,
-                                      const char *format, ...);
+                                      const char *format, ...)
+				      ATTRIBUTE_PRINTF(2,3);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatCDATA(xmlTextWriterPtr writer,
-                                       const char *format, va_list argptr);
+                                       const char *format, va_list argptr)
+				       ATTRIBUTE_PRINTF(2,0);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteCDATA(xmlTextWriterPtr writer,
                                 const xmlChar * content);
@@ -296,13 +314,15 @@
                                     const xmlChar * name,
                                     const xmlChar * pubid,
                                     const xmlChar * sysid,
-                                    const char *format, ...);
+                                    const char *format, ...)
+				    ATTRIBUTE_PRINTF(5,6);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatDTD(xmlTextWriterPtr writer,
                                      const xmlChar * name,
                                      const xmlChar * pubid,
                                      const xmlChar * sysid,
-                                     const char *format, va_list argptr);
+                                     const char *format, va_list argptr)
+				     ATTRIBUTE_PRINTF(5,0);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteDTD(xmlTextWriterPtr writer,
                               const xmlChar * name,
@@ -332,12 +352,14 @@
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteFormatDTDElement(xmlTextWriterPtr writer,
                                            const xmlChar * name,
-                                           const char *format, ...);
+                                           const char *format, ...)
+					   ATTRIBUTE_PRINTF(3,4);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatDTDElement(xmlTextWriterPtr writer,
                                             const xmlChar * name,
                                             const char *format,
-                                            va_list argptr);
+                                            va_list argptr)
+					    ATTRIBUTE_PRINTF(3,0);
     XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDElement(xmlTextWriterPtr
                                                        writer,
                                                        const xmlChar *
@@ -360,12 +382,14 @@
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteFormatDTDAttlist(xmlTextWriterPtr writer,
                                            const xmlChar * name,
-                                           const char *format, ...);
+                                           const char *format, ...)
+					   ATTRIBUTE_PRINTF(3,4);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatDTDAttlist(xmlTextWriterPtr writer,
                                             const xmlChar * name,
                                             const char *format,
-                                            va_list argptr);
+                                            va_list argptr)
+					    ATTRIBUTE_PRINTF(3,0);
     XMLPUBFUN int XMLCALL xmlTextWriterWriteDTDAttlist(xmlTextWriterPtr
                                                        writer,
                                                        const xmlChar *
@@ -389,13 +413,15 @@
         xmlTextWriterWriteFormatDTDInternalEntity(xmlTextWriterPtr writer,
                                                   int pe,
                                                   const xmlChar * name,
-                                                  const char *format, ...);
+                                                  const char *format, ...)
+						  ATTRIBUTE_PRINTF(4,5);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteVFormatDTDInternalEntity(xmlTextWriterPtr writer,
                                                    int pe,
                                                    const xmlChar * name,
                                                    const char *format,
-                                                   va_list argptr);
+                                                   va_list argptr)
+						   ATTRIBUTE_PRINTF(4,0);
     XMLPUBFUN int XMLCALL
         xmlTextWriterWriteDTDInternalEntity(xmlTextWriterPtr writer,
                                             int pe,
