mirror of
https://github.com/michaelrsweet/mxml.git
synced 2024-11-24 11:25:30 +00:00
CDATA nodes now omit the trailing "]]" for convenience (Issue #170)
This commit is contained in:
parent
4813db0209
commit
923dc965b9
@ -1,5 +1,6 @@
|
||||
# Changes in Mini-XML 2.11
|
||||
|
||||
- CDATA nodes now omit the trailing "]]" for convenience (Issue #170)
|
||||
- Fixed a memory leak in mxmlDelete (Issue #183)
|
||||
- mxmlElementSetAttrf did not work with some versions of Visual Studio
|
||||
(Issue #184)
|
||||
|
32
mxml-file.c
32
mxml-file.c
@ -1664,7 +1664,14 @@ mxml_load_data(
|
||||
while ((ch = (*getc_cb)(p, &encoding)) != EOF)
|
||||
{
|
||||
if (ch == '>' && !strncmp(bufptr - 2, "]]", 2))
|
||||
{
|
||||
/*
|
||||
* Drop terminator from CDATA string...
|
||||
*/
|
||||
|
||||
bufptr[-2] = '\0';
|
||||
break;
|
||||
}
|
||||
else if (mxml_add_char(ch, &bufptr, &buffer, &bufsize))
|
||||
goto error;
|
||||
}
|
||||
@ -2738,12 +2745,11 @@ mxml_write_node(mxml_node_t *node, /* I - Node to write */
|
||||
if ((*putc_cb)('<', p) < 0)
|
||||
return (-1);
|
||||
if (current->value.element.name[0] == '?' ||
|
||||
!strncmp(current->value.element.name, "!--", 3) ||
|
||||
!strncmp(current->value.element.name, "![CDATA[", 8))
|
||||
!strncmp(current->value.element.name, "!--", 3))
|
||||
{
|
||||
/*
|
||||
* Comments, CDATA, and processing instructions do not
|
||||
* use character entities.
|
||||
* Comments and processing instructions do not use character
|
||||
* entities.
|
||||
*/
|
||||
|
||||
const char *ptr; /* Pointer into name */
|
||||
@ -2752,6 +2758,24 @@ mxml_write_node(mxml_node_t *node, /* I - Node to write */
|
||||
if ((*putc_cb)(*ptr, p) < 0)
|
||||
return (-1);
|
||||
}
|
||||
else if (!strncmp(current->value.element.name, "![CDATA[", 8))
|
||||
{
|
||||
/*
|
||||
* CDATA elements do not use character entities, but also need the
|
||||
* "]]" terminator added at the end.
|
||||
*/
|
||||
|
||||
const char *ptr; /* Pointer into name */
|
||||
|
||||
for (ptr = current->value.element.name; *ptr; ptr ++)
|
||||
if ((*putc_cb)(*ptr, p) < 0)
|
||||
return (-1);
|
||||
|
||||
if ((*putc_cb)(']', p) < 0)
|
||||
return (-1);
|
||||
if ((*putc_cb)(']', p) < 0)
|
||||
return (-1);
|
||||
}
|
||||
else if (mxml_write_name(current->value.element.name, p, putc_cb) < 0)
|
||||
return (-1);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user