[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[xml] A problem with xmlTextReaderExpand in 2.5.11



Hi,

I have a problem with xmlTextReaderExpand. Attached test program gives
wrong output for 2.5.10 and 2.5.11. It works with libxml2 from CVS HEAD,
tough, so maybe this is only something for the test suite -- or it's me
doing something stupid in my program.

Attached are testcase.c [the test program] and test.xml [the test input
which shows the problem]. The bug is shown in the following output from
the programs [only showing the relevant part]:

-- output from 2.5.10/2.5.11:
tag #text type 14
1 children
<node id="33">
    </node>
tag #text type 14
tag ephy_bookmarks type 15

-- output from HEAD is as expected:
tag #text type 14
11 children
<node id="33">
    <property id="2" value_type="gchararray">Google</property>
    <property id="3"
value_type="gchararray">http://www.google.it/</property>
    <property id="9" value_type="gboolean">0</property>
    <parent id="0"/>
    <parent id="3"/>
  </node>
tag #text type 14
tag ephy_bookmarks type 15


As you can see, the problem is the children missing under the <node
id="33">.

Regards,
	Christian
#include <libxml/tree.h>
#include <libxml/xmlreader.h>
#include <glib.h>

#define XML_FILE "test.xml"

int main(void)
{
	xmlTextReaderPtr reader;
	int ret;

	reader = xmlNewTextReaderFilename (XML_FILE);

	ret = xmlTextReaderRead (reader);
	while (ret == 1)
	{
		xmlChar *name;
		xmlReaderTypes type;

		name = xmlTextReaderName (reader);
		type = xmlTextReaderNodeType (reader);

		if (xmlStrEqual (name, "node")
		    && type == XML_READER_TYPE_ELEMENT)
		{
			xmlNodePtr subtree, child;
			xmlBufferPtr buf;
			int count = 0;

			subtree = xmlTextReaderExpand (reader);

			for (child = subtree->children; child != 0; child = child->next, count++) ;

			buf = xmlBufferCreate ();
			xmlNodeDump (buf, subtree->doc, subtree, 0, 1);
			g_print ("%d children\n%s\n", count, buf->content);
			
			ret = xmlTextReaderNext (reader);
		}
		else
		{
			g_print ("tag %s type %d\n", name, type);
			ret = xmlTextReaderRead (reader);
		}
		xmlFree (name);
	}

	xmlFreeTextReader (reader);
}
<?xml version="1.0"?>
<ephy_bookmarks version="1.0">
<!--Do not rely on this file, it's only for internal use. Use bookmarks.rdf instead.-->
  <node id="30">
    <property id="5" value_type="gchararray">Entertainment</property>
    <property id="8" value_type="gint">2</property>
    <parent id="1"/>
  </node>
  <node id="31">
    <property id="5" value_type="gchararray">News</property>
    <property id="8" value_type="gint">2</property>
    <parent id="1"/>
  </node>
  <node id="33">
    <property id="2" value_type="gchararray">Google</property>
    <property id="3" value_type="gchararray">http://www.google.it/</property>
    <property id="9" value_type="gboolean">0</property>
    <parent id="0"/>
    <parent id="3"/>
  </node>
</ephy_bookmarks>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]