start adding API for escaping customization. Daniel

* xmlsave.c include/libxml/xmlsave.h: start adding API for
  escaping customization.
Daniel
diff --git a/ChangeLog b/ChangeLog
index 41e5385..d9f208e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat May 15 14:57:40 CEST 2004 Daniel Veillard <daniel@veillard.com>
+
+	* xmlsave.c include/libxml/xmlsave.h: start adding API for 
+	  escaping customization.
+
 Sat May 15 12:38:17 CEST 2004 Daniel Veillard <daniel@veillard.com>
 
 	* xmlsave.c: more xmlSave cleanup, optimization and refactoring
diff --git a/include/libxml/xmlsave.h b/include/libxml/xmlsave.h
index 1d43a71..d83038e 100644
--- a/include/libxml/xmlsave.h
+++ b/include/libxml/xmlsave.h
@@ -12,6 +12,7 @@
 
 #include <libxml/xmlversion.h>
 #include <libxml/tree.h>
+#include <libxml/encoding.h>
 #include <libxml/xmlIO.h>
 
 #ifdef LIBXML_OUTPUT_ENABLED
@@ -52,6 +53,12 @@
 		xmlSaveFlush		(xmlSaveCtxtPtr ctxt);
 XMLPUBFUN int XMLCALL
 		xmlSaveClose		(xmlSaveCtxtPtr ctxt);
+XMLPUBFUN int XMLCALL
+		xmlSaveSetEscape	(xmlSaveCtxtPtr ctxt,
+					 xmlCharEncodingOutputFunc escape);
+XMLPUBFUN int XMLCALL
+		xmlSaveSetAttrEscape	(xmlSaveCtxtPtr ctxt,
+					 xmlCharEncodingOutputFunc escape);
 #ifdef __cplusplus
 }
 #endif
diff --git a/xmlsave.c b/xmlsave.c
index 49268e6..5b43c97 100644
--- a/xmlsave.c
+++ b/xmlsave.c
@@ -83,9 +83,11 @@
     int options;
     int level;
     int format;
-    char indent[MAX_INDENT + 1];
+    char indent[MAX_INDENT + 1];	/* array for indenting output */
     int indent_nr;
     int indent_size;
+    xmlCharEncodingOutputFunc escape;	/* used for element content */
+    xmlCharEncodingOutputFunc escapeAttr;/* used for attribute content */
 };
 
 /************************************************************************
@@ -327,6 +329,8 @@
     int i;
 
     if (ctxt == NULL) return;
+    if ((ctxt->encoding == NULL) && (ctxt->escape == NULL))
+        ctxt->escape = xmlEscapeEntities;
     if (xmlTreeIndentString == NULL) {
         memset(&ctxt->indent[0], 0, MAX_INDENT + 1);
     } else {
@@ -382,6 +386,7 @@
 	    return(NULL);
 	}
         ret->encoding = xmlStrdup((const xmlChar *)encoding);
+	ret->escape = xmlEscapeEntities;
     }
     xmlSaveCtxtInit(ret);
 
@@ -646,12 +651,7 @@
 	    if ((cur->name == xmlStringText) ||
 		(cur->name != xmlStringTextNoenc)) {
 
-		if (ctxt->encoding == NULL) {
-		    xmlOutputBufferWriteEscape(buf, cur->content,
-		                               xmlEscapeEntities);
-		} else {
-		    xmlOutputBufferWriteEscape(buf, cur->content, NULL);
-		}
+                xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape);
 	    } else {
 		/*
 		 * Disable escaping, needed for XSLT
@@ -753,11 +753,7 @@
     }
     xmlOutputBufferWrite(buf, 1, ">");
     if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) {
-	if (ctxt->encoding == NULL) {
-	    xmlOutputBufferWriteEscape(buf, cur->content, xmlEscapeEntities);
-	} else {
-	    xmlOutputBufferWriteEscape(buf, cur->content, NULL);
-	}
+	xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape);
     }
     if (cur->children != NULL) {
 	if (ctxt->format) xmlOutputBufferWrite(buf, 1, "\n");
@@ -1092,13 +1088,7 @@
 	if (cur->content != NULL) {
 	    if ((cur->name == xmlStringText) ||
 		(cur->name != xmlStringTextNoenc)) {
-
-		if (ctxt->encoding == NULL) {
-		    xmlOutputBufferWriteEscape(buf, cur->content,
-		                               xmlEscapeEntities);
-		} else {
-		    xmlOutputBufferWriteEscape(buf, cur->content, NULL);
-		}
+                xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape);
 	    } else {
 		/*
 		 * Disable escaping, needed for XSLT
@@ -1214,11 +1204,7 @@
     }
     xmlOutputBufferWrite(buf, 1, ">");
     if ((cur->type != XML_ELEMENT_NODE) && (cur->content != NULL)) {
-	if (ctxt->encoding == NULL) {
-	    xmlOutputBufferWriteEscape(buf, cur->content, xmlEscapeEntities);
-	} else {
-	    xmlOutputBufferWriteEscape(buf, cur->content, NULL);
-	}
+	xmlOutputBufferWriteEscape(buf, cur->content, ctxt->escape);
     }
 
     /*
@@ -1498,6 +1484,40 @@
     return(ret);
 }
 
+/**
+ * xmlSaveSetEscape:
+ * @ctxt:  a document saving context
+ * @escape:  the escaping function
+ *
+ * Set a custom escaping function to be used for text in element content
+ *
+ * Returns 0 if successful or -1 in case of error.
+ */
+int
+xmlSaveSetEscape(xmlSaveCtxtPtr ctxt, xmlCharEncodingOutputFunc escape)
+{
+    if (ctxt == NULL) return(-1);
+    ctxt->escape = escape;
+    return(0);
+}
+
+/**
+ * xmlSaveSetAttrEscape:
+ * @ctxt:  a document saving context
+ * @escape:  the escaping function
+ *
+ * Set a custom escaping function to be used for text in attribute content
+ *
+ * Returns 0 if successful or -1 in case of error.
+ */
+int
+xmlSaveSetAttrEscape(xmlSaveCtxtPtr ctxt, xmlCharEncodingOutputFunc escape)
+{
+    if (ctxt == NULL) return(-1);
+    ctxt->escapeAttr = escape;
+    return(0);
+}
+
 /************************************************************************
  *									*
  *		Public entry points based on buffers			*