From 2f4be485272446109e4451a19dc29ba6728f0039 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 15 Jul 2012 18:26:47 +0100 Subject: XML Binding: Allow expat handler to coalesce TEXT nodes. Core suite now passes with expat. --- bindings/xml/expat_xmlparser.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'bindings') diff --git a/bindings/xml/expat_xmlparser.c b/bindings/xml/expat_xmlparser.c index 7f4fa03..1077bc9 100644 --- a/bindings/xml/expat_xmlparser.c +++ b/bindings/xml/expat_xmlparser.c @@ -159,7 +159,8 @@ expat_xmlparser_cdata_handler(void *_parser, dom_xml_parser *parser = _parser; dom_string *data; dom_exception err; - struct dom_node *cdata, *ins_cdata; + struct dom_node *cdata, *ins_cdata, *lastchild = NULL; + dom_node_type ntype = 0; err = dom_string_create((const uint8_t *)s, len, &data); if (err != DOM_NO_ERR) { @@ -168,6 +169,39 @@ expat_xmlparser_cdata_handler(void *_parser, return; } + err = dom_node_get_last_child(parser->current, &lastchild); + + if (err == DOM_NO_ERR && lastchild != NULL) { + err = dom_node_get_node_type(lastchild, &ntype); + } + + if (err != DOM_NO_ERR) { + dom_string_unref(data); + if (lastchild != NULL) + dom_node_unref(lastchild); + parser->msg(DOM_MSG_CRITICAL, parser->mctx, + "No memory for cdata section"); + return; + } + + if (ntype == DOM_TEXT_NODE && parser->is_cdata == false) { + /* We can append this text instead */ + err = dom_characterdata_append_data( + (dom_characterdata *)lastchild, data); + dom_string_unref(data); + if (lastchild != NULL) + dom_node_unref(lastchild); + if (err != DOM_NO_ERR) { + parser->msg(DOM_MSG_CRITICAL, parser->mctx, + "No memory for cdata section"); + } + return; + } + + if (lastchild != NULL) + dom_node_unref(lastchild); + + /* We can't append directly, so make a new node */ err = parser->is_cdata ? dom_document_create_cdata_section(parser->doc, data, (dom_cdata_section **)&cdata) : -- cgit v1.2.3