Re: [xml] xmlReaderForIO



Daniel Veillard wrote:

On Mon, May 03, 2004 at 04:18:08PM +0200, Minor Gordon wrote:
Hello,

I am trying to use xmlReaderForIO() to read from some custom buffer structures. I couldn't find any examples of this in the documentation, so I'm winging it.

 http://xmlsoft.org/examples/io1.c
 gives a somewhat similar example even if it does not use that API.

For the IO reader, I have:
xmlTextReaderPtr reader = xmlReaderForIO((xmlInputReadCallback)xmlReadBuffers,NULL,NULL,"sbns", NULL, 0);

which I've tried in several variations (giving an encoding "utf-8", makin a dummy close callback, passing an object in ioctx, etc.). This is the variation I want.

The function xmlReadBuffers has the signature:
int xmlReadBuffers(void * context, char * buffer, int len)

When the program hits the first line (reader = ) it jumps into nowhere. Not exactly nowhere -- access violation at 0x00000010. Like it's trying to access an element of an array that's actually a NULL pointer. I don't think it's an environment problem, because the file reader works (so the DLLs are loading).

Is there something with the code?

Impossible to say without seeing the code. Make sure first that the given example work in your environemnt then if yes,
the best thing is to use a debugger to trace what's happening.

Hello,

The problem turned out to be multi-threading.
I switched to the libxml2_a.lib and it worked..

I've looked at the I/O examples and header file. The example you pointed out has this function:

static int
sqlRead(void * context, char * buffer, int len) {
  const char *ptr = (const char *) context;

  if ((context == NULL) || (buffer == NULL) || (len < 0))
      return(-1);

  if (len > rlen) len = rlen;
  memcpy(buffer, ptr, len);
  rlen -= len;
  return(len);
}


which looks good.
However,
I don't want to be given an allocated buffer to fill. I already have the XML in memory, and I simply want to return a buffer and tell libxml2 how long it is. No copy.

Is that possible?  Surely someone else has done this..

Thank you for your help.

Minor










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