diff -ru orig/mxml-2.6/mxml-file.c mxml-2.6/mxml-file.c --- orig/mxml-2.6/mxml-file.c 2009-05-17 07:20:52.000000000 +0200 +++ mxml-2.6/mxml-file.c 2009-06-04 21:39:30.233646978 +0200 @@ -32,7 +32,8 @@ * using a SAX callback. * mxmlSetCustomHandlers() - Set the handling functions for custom data. * mxmlSetErrorCallback() - Set the error message callback. - * mxmlSetWrapMargin() - Set the the wrap margin when saving XML data. + * mxmlSetWrapMargin() - Set the wrap margin when saving XML data. + * mxmlSetEmitShortEmpty() - Set the preference for emitting shorthand empty elements. * mxml_add_char() - Add a character to a buffer, expanding as needed. * mxml_fd_getc() - Read a character from a file descriptor. * mxml_fd_putc() - Write a character to a file descriptor. @@ -602,7 +603,7 @@ /* - * 'mxmlSetWrapMargin()' - Set the the wrap margin when saving XML data. + * 'mxmlSetWrapMargin()' - Set the wrap margin when saving XML data. * * Wrapping is disabled when "column" is 0. * @@ -621,6 +622,26 @@ /* + * 'mxmlSetEmitShortEmpty()' - Set the preference for emitting shorthand empty elements. + * + * Emit shorthand empty elements () when enabled is 1, + * long form () when enabled is 0. + * + * @since Mini-XML 2.7@ + */ + +void +mxmlSetEmitShortEmpty(int enabled) /* I - Preference for emitting shorthand empty elements, 0 to disable */ +{ + _mxml_global_t *global = _mxml_global(); + /* Global data */ + + + global->emit_short_empty = enabled; +} + + +/* * 'mxml_add_char()' - Add a character to a buffer, expanding as needed. */ @@ -2818,16 +2839,42 @@ } else { - if ((*putc_cb)(' ', p) < 0) - return (-1); - if ((*putc_cb)('/', p) < 0) - return (-1); - if ((*putc_cb)('>', p) < 0) - return (-1); + if (global->emit_short_empty) + { + if ((*putc_cb)(' ', p) < 0) + return (-1); + if ((*putc_cb)('/', p) < 0) + return (-1); + if ((*putc_cb)('>', p) < 0) + return (-1); - col += 3; + col += 3; + col = mxml_write_ws(node, p, cb, MXML_WS_AFTER_OPEN, col, putc_cb); + } + else + { + if ((*putc_cb)('>', p) < 0) + return (-1); - col = mxml_write_ws(node, p, cb, MXML_WS_AFTER_OPEN, col, putc_cb); + /* + * No added whitespace between opening and closing tags + * because this is an empty element + */ + + if ((*putc_cb)('<', p) < 0) + return (-1); + if ((*putc_cb)('/', p) < 0) + return (-1); + + if (mxml_write_name(node->value.element.name, p, putc_cb) < 0) + return (-1); + + if ((*putc_cb)('>', p) < 0) + return (-1); + + col += strlen(node->value.element.name) + 4; + col = mxml_write_ws(node, p, cb, MXML_WS_AFTER_CLOSE, col, putc_cb); + } } break; diff -ru orig/mxml-2.6/mxml-private.c mxml-2.6/mxml-private.c --- orig/mxml-2.6/mxml-private.c 2007-11-22 19:01:52.000000000 +0100 +++ mxml-2.6/mxml-private.c 2009-06-04 21:15:48.869658398 +0200 @@ -155,6 +155,7 @@ global->num_entity_cbs = 1; global->entity_cbs[0] = _mxml_entity_cb; global->wrap = 72; + global->emit_short_empty = 1; } return (global); @@ -248,6 +249,7 @@ global->num_entity_cbs = 1; global->entity_cbs[0] = _mxml_entity_cb; global->wrap = 72; + global->emit_short_empty = 1; TlsSetValue(_mxml_tls_index, (LPVOID)global); } @@ -270,6 +272,7 @@ 1, /* num_entity_cbs */ { _mxml_entity_cb }, /* entity_cbs */ 72, /* wrap */ + 1, /* emit_short_empty */ NULL, /* custom_load_cb */ NULL /* custom_save_cb */ }; diff -ru orig/mxml-2.6/mxml-private.h mxml-2.6/mxml-private.h --- orig/mxml-2.6/mxml-private.h 2007-09-21 06:46:02.000000000 +0200 +++ mxml-2.6/mxml-private.h 2009-06-04 21:14:40.765781519 +0200 @@ -34,6 +34,7 @@ int num_entity_cbs; int (*entity_cbs[100])(const char *name); int wrap; + int emit_short_empty; mxml_custom_load_cb_t custom_load_cb; mxml_custom_save_cb_t custom_save_cb; } _mxml_global_t; diff -ru orig/mxml-2.6/mxml.h mxml-2.6/mxml.h --- orig/mxml-2.6/mxml.h 2009-03-19 06:38:52.000000000 +0100 +++ mxml-2.6/mxml.h 2009-06-04 21:23:12.557657447 +0200 @@ -276,6 +276,7 @@ # endif /* __GNUC__ */ ; extern void mxmlSetWrapMargin(int column); +extern void mxmlSetEmitShortEmpty(int enabled); extern mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top, int descend); extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top,