[xml] Question about xmlReader...



Hi,

I'm using libxml2-2.6.9-win32 from www.zlatkovic.com.

I've been playing around with the xmlReader, and have been having problems with a segfault. The following contrived example illustrates simply what happens in my larger program. This code segfaults on the last call to xmlTextReaderRead.

#include <stdio.h>
#include <libxml/xmlreader.h>

void test(void) {
  int nRc;
  xmlTextReaderPtr reader;
  char msg[] = "<element1><element2>data</element2></element1>";

  reader = xmlReaderForMemory(msg,strlen(msg),NULL,NULL,XML_PARSE_RECOVER);
  nRc = xmlTextReaderRead(reader);

  while (1 == nRc) {
    xmlChar *name = xmlTextReaderName(reader);
    if (NULL != name) {
      xmlFree(name);
    }
    nRc = xmlTextReaderRead(reader);
  }
  nRc = xmlTextReaderRead(reader);  /* segfault */
  xmlFreeTextReader(reader);
}

Is this the expected behaviour, or should xmlTextReaderRead return 0 or -1?

Scott



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