Blame doc/examples/parse3.c

Packit Service a31ea6
/**
Packit Service a31ea6
 * section: Parsing
Packit Service a31ea6
 * synopsis: Parse an XML document in memory to a tree and free it
Packit Service a31ea6
 * purpose: Demonstrate the use of xmlReadMemory() to read an XML file
Packit Service a31ea6
 *          into a tree and and xmlFreeDoc() to free the resulting tree
Packit Service a31ea6
 * usage: parse3
Packit Service a31ea6
 * test: parse3
Packit Service a31ea6
 * author: Daniel Veillard
Packit Service a31ea6
 * copy: see Copyright for the status of this software.
Packit Service a31ea6
 */
Packit Service a31ea6
Packit Service a31ea6
#include <stdio.h>
Packit Service a31ea6
#include <libxml/parser.h>
Packit Service a31ea6
#include <libxml/tree.h>
Packit Service a31ea6
Packit Service a31ea6
static const char *document = "<doc/>";
Packit Service a31ea6
Packit Service a31ea6
/**
Packit Service a31ea6
 * example3Func:
Packit Service a31ea6
 * @content: the content of the document
Packit Service a31ea6
 * @length: the length in bytes
Packit Service a31ea6
 *
Packit Service a31ea6
 * Parse the in memory document and free the resulting tree
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
example3Func(const char *content, int length) {
Packit Service a31ea6
    xmlDocPtr doc; /* the resulting document tree */
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * The document being in memory, it have no base per RFC 2396,
Packit Service a31ea6
     * and the "noname.xml" argument will serve as its base.
Packit Service a31ea6
     */
Packit Service a31ea6
    doc = xmlReadMemory(content, length, "noname.xml", NULL, 0);
Packit Service a31ea6
    if (doc == NULL) {
Packit Service a31ea6
        fprintf(stderr, "Failed to parse document\n");
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
    xmlFreeDoc(doc);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
int main(void) {
Packit Service a31ea6
    /*
Packit Service a31ea6
     * this initialize the library and check potential ABI mismatches
Packit Service a31ea6
     * between the version it was compiled for and the actual shared
Packit Service a31ea6
     * library used.
Packit Service a31ea6
     */
Packit Service a31ea6
    LIBXML_TEST_VERSION
Packit Service a31ea6
Packit Service a31ea6
    example3Func(document, 6);
Packit Service a31ea6
Packit Service a31ea6
    /*
Packit Service a31ea6
     * Cleanup function for the XML library.
Packit Service a31ea6
     */
Packit Service a31ea6
    xmlCleanupParser();
Packit Service a31ea6
    /*
Packit Service a31ea6
     * this is to debug memory for regression tests
Packit Service a31ea6
     */
Packit Service a31ea6
    xmlMemoryDump();
Packit Service a31ea6
    return(0);
Packit Service a31ea6
}