summaryrefslogtreecommitdiff
path: root/bindings/xml
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-15 18:26:47 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-07-15 18:26:47 +0100
commit2f4be485272446109e4451a19dc29ba6728f0039 (patch)
tree56d43f0cfe4f7911293a77e453989d543ad25e79 /bindings/xml
parente31173cd5d116a49d3c11ab732e639ca3cc3ecd1 (diff)
downloadlibdom-2f4be485272446109e4451a19dc29ba6728f0039.tar.gz
libdom-2f4be485272446109e4451a19dc29ba6728f0039.tar.bz2
XML Binding: Allow expat handler to coalesce TEXT nodes. Core suite now passes with expat.
Diffstat (limited to 'bindings/xml')
-rw-r--r--bindings/xml/expat_xmlparser.c36
1 files changed, 35 insertions, 1 deletions
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) :