libxml2 r3794 - in trunk: . include/libxml



Author: veillard
Date: Thu Sep 25 14:31:40 2008
New Revision: 3794
URL: http://svn.gnome.org/viewvc/libxml2?rev=3794&view=rev

Log:
* include/libxml/xmlsave.h xmlsave.c: new options to serialize
  as XML/HTML/XHTML and restore old entry point behaviours
Daniel


Modified:
   trunk/ChangeLog
   trunk/include/libxml/xmlsave.h
   trunk/xmlsave.c

Modified: trunk/include/libxml/xmlsave.h
==============================================================================
--- trunk/include/libxml/xmlsave.h	(original)
+++ trunk/include/libxml/xmlsave.h	Thu Sep 25 14:31:40 2008
@@ -30,7 +30,10 @@
     XML_SAVE_FORMAT     = 1<<0,	/* format save output */
     XML_SAVE_NO_DECL    = 1<<1,	/* drop the xml declaration */
     XML_SAVE_NO_EMPTY	= 1<<2, /* no empty tags */
-    XML_SAVE_NO_XHTML	= 1<<3  /* disable XHTML1 specific rules */
+    XML_SAVE_NO_XHTML	= 1<<3, /* disable XHTML1 specific rules */
+    XML_SAVE_XHTML	= 1<<4, /* force XHTML1 specific rules */
+    XML_SAVE_AS_XML     = 1<<5, /* force XML serialization on HTML doc */
+    XML_SAVE_AS_HTML    = 1<<6  /* force HTML serialization on XML doc */
 } xmlSaveOption;
 
 

Modified: trunk/xmlsave.c
==============================================================================
--- trunk/xmlsave.c	(original)
+++ trunk/xmlsave.c	Thu Sep 25 14:31:40 2008
@@ -757,8 +757,14 @@
 	return;
     }
 #ifdef LIBXML_HTML_ENABLED
-    if ((cur->type != XML_NAMESPACE_DECL) && (cur->doc != NULL) &&
-        (cur->doc->type == XML_HTML_DOCUMENT_NODE)) {
+    if (ctxt->options & XML_SAVE_XHTML) {
+        xhtmlNodeDumpOutput(ctxt, cur);
+        return;
+    }
+    if (((cur->type != XML_NAMESPACE_DECL) && (cur->doc != NULL) &&
+         (cur->doc->type == XML_HTML_DOCUMENT_NODE) &&
+         ((ctxt->options & XML_SAVE_AS_XML) == 0)) ||
+        (ctxt->options & XML_SAVE_AS_HTML)) {
 	htmlNodeDumpOutputInternal(ctxt, cur);
 	return;
     }
@@ -953,7 +959,10 @@
 		     xmlGetCharEncodingName((xmlCharEncoding) cur->charset);
     }
 
-    if (cur->type == XML_HTML_DOCUMENT_NODE) {
+    if (((cur->type == XML_HTML_DOCUMENT_NODE) &&
+         ((ctxt->options & XML_SAVE_AS_XML) == 0) &&
+         ((ctxt->options & XML_SAVE_XHTML) == 0)) ||
+        (ctxt->options & XML_SAVE_AS_HTML)) {
 #ifdef LIBXML_HTML_ENABLED
         if (encoding != NULL)
 	    htmlSetMetaEncoding(cur, (const xmlChar *) encoding);
@@ -981,7 +990,9 @@
 #else
         return(-1);
 #endif
-    } else if (cur->type == XML_DOCUMENT_NODE) {
+    } else if ((cur->type == XML_DOCUMENT_NODE) ||
+               (ctxt->options & XML_SAVE_AS_XML) ||
+               (ctxt->options & XML_SAVE_XHTML)) {
 	enc = xmlParseCharEncoding((const char*) encoding);
 	if ((encoding != NULL) && (oldctxtenc == NULL) &&
 	    (buf->encoder == NULL) && (buf->conv == NULL) &&
@@ -1032,6 +1043,8 @@
 	}
 
 #ifdef LIBXML_HTML_ENABLED
+        if (ctxt->options & XML_SAVE_XHTML)
+            is_xhtml = 1;
 	if ((ctxt->options & XML_SAVE_NO_XHTML) == 0) {
 	    dtd = xmlGetIntSubset(cur);
 	    if (dtd != NULL) {
@@ -2123,6 +2136,7 @@
     ctxt.format = format;
     ctxt.encoding = (const xmlChar *) encoding;
     xmlSaveCtxtInit(&ctxt);
+    ctxt.options |= XML_SAVE_AS_XML;
 
 #ifdef LIBXML_HTML_ENABLED
     dtd = xmlGetIntSubset(doc);
@@ -2208,6 +2222,7 @@
     ctxt.format = format;
     ctxt.encoding = (const xmlChar *) txt_encoding;
     xmlSaveCtxtInit(&ctxt);
+    ctxt.options |= XML_SAVE_AS_XML;
     xmlDocContentDumpOutput(&ctxt, out_doc);
     xmlOutputBufferFlush(out_buff);
     if (out_buff->conv != NULL) {
@@ -2326,6 +2341,7 @@
     ctxt.format = format;
     ctxt.encoding = (const xmlChar *) encoding;
     xmlSaveCtxtInit(&ctxt);
+    ctxt.options |= XML_SAVE_AS_XML;
     xmlDocContentDumpOutput(&ctxt, cur);
 
     ret = xmlOutputBufferClose(buf);
@@ -2375,6 +2391,7 @@
     ctxt.format = 0;
     ctxt.encoding = (const xmlChar *) encoding;
     xmlSaveCtxtInit(&ctxt);
+    ctxt.options |= XML_SAVE_AS_XML;
     xmlDocContentDumpOutput(&ctxt, cur);
     ret = xmlOutputBufferClose(buf);
     return(ret);
@@ -2414,6 +2431,7 @@
     ctxt.format = format;
     ctxt.encoding = (const xmlChar *) encoding;
     xmlSaveCtxtInit(&ctxt);
+    ctxt.options |= XML_SAVE_AS_XML;
     xmlDocContentDumpOutput(&ctxt, cur);
     ret = xmlOutputBufferClose(buf);
     return (ret);
@@ -2468,6 +2486,7 @@
     ctxt.format = format;
     ctxt.encoding = (const xmlChar *) encoding;
     xmlSaveCtxtInit(&ctxt);
+    ctxt.options |= XML_SAVE_AS_XML;
 
     xmlDocContentDumpOutput(&ctxt, cur);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]