diff --git a/ChangeLog b/ChangeLog index 688f2cff..a6a95cc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Sep 12 14:14:12 CEST 2005 Rob Richards + + * include/libxml/xmlsave.h xmlsave.c: add XML_SAVE_NO_EMPTY save option + and use option from xmlSaveCtxtPtr rather than global during output. + * xmlsave.c: fix some output formatting for meta element under XHTML. + Mon Sep 12 11:12:03 CEST 2005 Daniel Veillard * include/libxml/parser.h parser.c xmllint.c: damn XML_FEATURE_UNICODE diff --git a/include/libxml/xmlsave.h b/include/libxml/xmlsave.h index 7b8f42c3..0f386ab4 100644 --- a/include/libxml/xmlsave.h +++ b/include/libxml/xmlsave.h @@ -28,7 +28,8 @@ extern "C" { */ typedef enum { XML_SAVE_FORMAT = 1<<0, /* format save output */ - XML_SAVE_NO_DECL = 1<<1 /* drop the xml declaration */ + XML_SAVE_NO_DECL = 1<<1, /* drop the xml declaration */ + XML_SAVE_NO_EMPTY = 1<<2 /* no empty tags */ } xmlSaveOption; diff --git a/xmlsave.c b/xmlsave.c index 75f76a05..fe5795e1 100644 --- a/xmlsave.c +++ b/xmlsave.c @@ -343,6 +343,10 @@ xmlSaveCtxtInit(xmlSaveCtxtPtr ctxt) ctxt->indent_size); ctxt->indent[ctxt->indent_nr * ctxt->indent_size] = 0; } + + if (xmlSaveNoEmptyTags) { + ctxt->options |= XML_SAVE_NO_EMPTY; + } } /** @@ -380,13 +384,6 @@ xmlNewSaveCtxt(const char *encoding, int options) } memset(ret, 0, sizeof(xmlSaveCtxt)); - /* - * Use the options - */ - ret->options = options; - if (options & XML_SAVE_FORMAT) - ret->format = 1; - if (encoding != NULL) { ret->handler = xmlFindCharEncodingHandler(encoding); if (ret->handler == NULL) { @@ -399,6 +396,19 @@ xmlNewSaveCtxt(const char *encoding, int options) } xmlSaveCtxtInit(ret); + /* + * Use the options + */ + + /* Re-check this option as it may already have been set */ + if ((ret->options & XML_SAVE_NO_EMPTY) && ! (options & XML_SAVE_NO_EMPTY)) { + options |= XML_SAVE_NO_EMPTY; + } + + ret->options = options; + if (options & XML_SAVE_FORMAT) + ret->format = 1; + return(ret); } @@ -773,7 +783,7 @@ xmlNodeDumpOutputInternal(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { xmlAttrListDumpOutput(ctxt, cur->properties); if (((cur->type == XML_ELEMENT_NODE) || (cur->content == NULL)) && - (cur->children == NULL) && (!xmlSaveNoEmptyTags)) { + (cur->children == NULL) && ((ctxt->options & XML_SAVE_NO_EMPTY) == 0)) { xmlOutputBufferWrite(buf, 2, "/>"); ctxt->format = format; return; @@ -1245,6 +1255,13 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { } else { if (addmeta == 1) { xmlOutputBufferWrite(buf, 1, ">"); + if (ctxt->format) { + xmlOutputBufferWrite(buf, 1, "\n"); + if (xmlIndentTreeOutput) + xmlOutputBufferWrite(buf, ctxt->indent_size * + (ctxt->level + 1 > ctxt->indent_nr ? + ctxt->indent_nr : ctxt->level + 1), ctxt->indent); + } xmlOutputBufferWriteString(buf, ""); + if (ctxt->format) + xmlOutputBufferWrite(buf, 1, "\n"); + } else { + xmlOutputBufferWrite(buf, 1, ">"); } /* * C.3. Element Minimization and Empty Element Content */ - xmlOutputBufferWrite(buf, 3, ">ns != NULL) && (cur->ns->prefix != NULL)) { xmlOutputBufferWriteString(buf, (const char *)cur->ns->prefix); xmlOutputBufferWrite(buf, 1, ":"); @@ -1269,6 +1290,13 @@ xhtmlNodeDumpOutput(xmlSaveCtxtPtr ctxt, xmlNodePtr cur) { } xmlOutputBufferWrite(buf, 1, ">"); if (addmeta == 1) { + if (ctxt->format) { + xmlOutputBufferWrite(buf, 1, "\n"); + if (xmlIndentTreeOutput) + xmlOutputBufferWrite(buf, ctxt->indent_size * + (ctxt->level + 1 > ctxt->indent_nr ? + ctxt->indent_nr : ctxt->level + 1), ctxt->indent); + } xmlOutputBufferWriteString(buf, "