Blame doc/examples/parse1.c

Packit Service a31ea6
/**
Packit Service a31ea6
 * section: Parsing
Packit Service a31ea6
 * synopsis: Parse an XML file to a tree and free it
Packit Service a31ea6
 * purpose: Demonstrate the use of xmlReadFile() to read an XML file
Packit Service a31ea6
 *          into a tree and and xmlFreeDoc() to free the resulting tree
Packit Service a31ea6
 * usage: parse1 test1.xml
Packit Service a31ea6
 * test: parse1 test1.xml
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
/**
Packit Service a31ea6
 * example1Func:
Packit Service a31ea6
 * @filename: a filename or an URL
Packit Service a31ea6
 *
Packit Service a31ea6
 * Parse the resource and free the resulting tree
Packit Service a31ea6
 */
Packit Service a31ea6
static void
Packit Service a31ea6
example1Func(const char *filename) {
Packit Service a31ea6
    xmlDocPtr doc; /* the resulting document tree */
Packit Service a31ea6
Packit Service a31ea6
    doc = xmlReadFile(filename, NULL, 0);
Packit Service a31ea6
    if (doc == NULL) {
Packit Service a31ea6
        fprintf(stderr, "Failed to parse %s\n", filename);
Packit Service a31ea6
	return;
Packit Service a31ea6
    }
Packit Service a31ea6
    xmlFreeDoc(doc);
Packit Service a31ea6
}
Packit Service a31ea6
Packit Service a31ea6
int main(int argc, char **argv) {
Packit Service a31ea6
    if (argc != 2)
Packit Service a31ea6
        return(1);
Packit Service a31ea6
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
    example1Func(argv[1]);
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
}