svnno****@sourc*****
svnno****@sourc*****
Wed Jan 9 21:42:31 JST 2008
Revision: 3352 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3352 Author: furyo Date: 2008-01-09 21:42:30 +0900 (Wed, 09 Jan 2008) Log Message: ----------- * src/kz-xml.c: Fix a bug a xml data written with "CDATA" was not parsed. (ex. kernel.org RSS http://kernel.org/kdist/rss.xml ) Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/src/kz-xml.c Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2008-01-07 11:06:21 UTC (rev 3351) +++ kazehakase/trunk/ChangeLog 2008-01-09 12:42:30 UTC (rev 3352) @@ -1,3 +1,8 @@ +2008-01-09 Ryo SHIMIZU <furyo****@on-ai*****> + + * src/kz-xml.c: Fix a bug a xml data written with "CDATA" was + not parsed. (ex. kernel.org RSS http://kernel.org/kdist/rss.xml ) + 2008-01-07 Kouhei Sutou <kou****@cozmi*****> * configure.ac: added module/embed/gecko/gtkmozembed/Makefile. Modified: kazehakase/trunk/src/kz-xml.c =================================================================== --- kazehakase/trunk/src/kz-xml.c 2008-01-07 11:06:21 UTC (rev 3351) +++ kazehakase/trunk/src/kz-xml.c 2008-01-09 12:42:30 UTC (rev 3352) @@ -36,6 +36,7 @@ static void dispose (GObject *object); static void kz_xml_attr_free (KzXMLAttr *attr); +gchar *get_cdata_as_plaintext(gpointer content); G_DEFINE_TYPE(KzXML, kz_xml, G_TYPE_OBJECT) @@ -497,6 +498,12 @@ g_free(escaped); } } + else if (node->type == KZ_XML_NODE_CDATA) + { + gchar *cdata_text = get_cdata_as_plaintext(node->content); + g_string_append(gstr, cdata_text); + g_free(cdata_text); + } else { g_string_append(gstr, node->content); @@ -529,7 +536,14 @@ if (node->type == KZ_XML_NODE_TEXT) g_string_append(gstr, node->content); + if (node->type == KZ_XML_NODE_CDATA) + { + gchar *cdata_text = get_cdata_as_plaintext(node->content); + g_string_append(gstr, cdata_text); + g_free(cdata_text); + } + for (list = node->children; list; list = g_list_next(list)) kz_xml_node_append_string(list->data, gstr); } @@ -1035,3 +1049,32 @@ kz_xml_node_arrange_indent(node, indent_level + 1); } } + +gchar * +get_cdata_as_plaintext(gpointer content) +{ + gchar *cdata_text; + gchar *plain_text; + gchar *str; + gint i, j; + + str = (char*)content; + + i = j = strlen("<![CDATA["); + while(str[i] != '\0') + { + if(str[i] == ']' && str[i+3] == '\0') + { + break; + } + i++; + } + + cdata_text = g_strndup(str+j, i-j); + plain_text = remove_tag((const gchar*)cdata_text, (gsize)strlen(cdata_text)); + + if(cdata_text) + g_free(cdata_text); + + return plain_text; +}