Annotation of embedaddon/libxml2/doc/examples/io2.c, revision 1.1

1.1     ! misho       1: /**
        !             2:  * section: InputOutput
        !             3:  * synopsis: Output to char buffer
        !             4:  * purpose: Demonstrate the use of xmlDocDumpMemory
        !             5:  *          to output document to a character buffer
        !             6:  * usage: io2
        !             7:  * test: io2 > io2.tmp ; diff io2.tmp io2.res ; rm -f io2.tmp
        !             8:  * author: John Fleck
        !             9:  * copy: see Copyright for the status of this software.
        !            10:  */
        !            11: 
        !            12: #include <libxml/parser.h>
        !            13: 
        !            14: #if defined(LIBXML_TREE_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
        !            15: int
        !            16: main(void)
        !            17: {
        !            18: 
        !            19:     xmlNodePtr n;
        !            20:     xmlDocPtr doc;
        !            21:     xmlChar *xmlbuff;
        !            22:     int buffersize;
        !            23: 
        !            24:     /*
        !            25:      * Create the document.
        !            26:      */
        !            27:     doc = xmlNewDoc(BAD_CAST "1.0");
        !            28:     n = xmlNewNode(NULL, BAD_CAST "root");
        !            29:     xmlNodeSetContent(n, BAD_CAST "content");
        !            30:     xmlDocSetRootElement(doc, n);
        !            31: 
        !            32:     /*
        !            33:      * Dump the document to a buffer and print it
        !            34:      * for demonstration purposes.
        !            35:      */
        !            36:     xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
        !            37:     printf("%s", (char *) xmlbuff);
        !            38: 
        !            39:     /*
        !            40:      * Free associated memory.
        !            41:      */
        !            42:     xmlFree(xmlbuff);
        !            43:     xmlFreeDoc(doc);
        !            44: 
        !            45:     return (0);
        !            46: 
        !            47: }
        !            48: #else
        !            49: #include <stdio.h>
        !            50: 
        !            51: int
        !            52: main(void)
        !            53: {
        !            54:     fprintf(stderr,
        !            55:             "library not configured with tree and output support\n");
        !            56:     return (1);
        !            57: }
        !            58: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>