Re: [xml] xmlDocDump( FILE *, xmlDocPtr )

Date view Thread view Subject view Author view

From: Daniel Veillard (Daniel.Veillard@w3.org)
Date: Wed Aug 30 2000 - 10:37:53 EDT


On Wed, Aug 30, 2000 at 10:53:47AM +0100, Andrew Logan wrote:
>
> Hi,
>
> Can somebody explain why xmlDocDump() closes the the file pointer when it
> has finished writing?

  Humm, yes, this doesn't make much sense actually since the FILE *
is inherited.
  I wonder if changing this would break existing applications...

> I thought this could be a simple way of dumping an in-memory XML document
> down a network channel to a server.

  There is another (easy) way to have total control over the output
used, use the I/O handlers:
   http://xmlsoft.org/html/gnome-xml-xmlio.html

  Define you own I/O handler allocator
------------------------------------
xmlOutputBufferPtr
xmlOutputBufferCreateOwn(FILE *file, xmlCharEncodingHandlerPtr encoder) {
    xmlOutputBufferPtr ret;
    
    if (xmlOutputCallbackInitialized == 0)
        xmlRegisterDefaultOutputCallbacks();
    
    if (file == NULL) return(NULL);

    ret = xmlAllocOutputBuffer(encoder);
    if (ret != NULL) {
        ret->context = file;
        ret->writecallback = xmlFileWrite;
        ret->closecallback = NULL; /* No close callback */
    }

    return(ret);
}
------------------------------------

call it to get an OutputBuffer and then use the following function to
save to this buffer.

int xmlSaveFileTo (xmlOutputBuffer *buf, xmlDocPtr cur, const char *encoding);

  I agree the I/O handlers aren't well documented, but basically they
allow you to totally control how you load and save documents.

Daniel

-- 
Daniel.Veillard@w3.org | W3C, INRIA Rhone-Alpes  | Today's Bookmarks :
Tel : +33 476 615 257  | 655, avenue de l'Europe | Linux XML libxml WWW
Fax : +33 476 615 207  | 38330 Montbonnot FRANCE | Gnome rpm2html rpmfind
 http://www.w3.org/People/all#veillard%40w3.org  | RPM badminton Kaffe
----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Aug 30 2000 - 09:43:50 EDT