new options to serialize as XML/HTML/XHTML and restore old entry point
* include/libxml/xmlsave.h xmlsave.c: new options to serialize
as XML/HTML/XHTML and restore old entry point behaviours
Daniel
svn path=/trunk/; revision=3794
diff --git a/ChangeLog b/ChangeLog
index 2ef2cc7..518e113 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Sep 25 16:30:11 CEST 2008 Daniel Veillard <daniel@veillard.com>
+
+ * include/libxml/xmlsave.h xmlsave.c: new options to serialize
+ as XML/HTML/XHTML and restore old entry point behaviours
+
Mon Sep 1 16:49:05 CEST 2008 Daniel Veillard <daniel@veillard.com>
* doc/xml.html doc/news.html configure.in python/setup.py NEWS:
diff --git a/include/libxml/xmlsave.h b/include/libxml/xmlsave.h
index c71c71a..4201b4d 100644
--- a/include/libxml/xmlsave.h
+++ b/include/libxml/xmlsave.h
@@ -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;
diff --git a/xmlsave.c b/xmlsave.c
index a650722..53b23e6 100644
--- a/xmlsave.c
+++ b/xmlsave.c
@@ -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);