Blame doc/examples/parse1.c

Packit 423ecb
/**
Packit 423ecb
 * section: Parsing
Packit 423ecb
 * synopsis: Parse an XML file to a tree and free it
Packit 423ecb
 * purpose: Demonstrate the use of xmlReadFile() to read an XML file
Packit 423ecb
 *          into a tree and and xmlFreeDoc() to free the resulting tree
Packit 423ecb
 * usage: parse1 test1.xml
Packit 423ecb
 * test: parse1 test1.xml
Packit 423ecb
 * author: Daniel Veillard
Packit 423ecb
 * copy: see Copyright for the status of this software.
Packit 423ecb
 */
Packit 423ecb
Packit 423ecb
#include <stdio.h>
Packit 423ecb
#include <libxml/parser.h>
Packit 423ecb
#include <libxml/tree.h>
Packit 423ecb
Packit 423ecb
/**
Packit 423ecb
 * example1Func:
Packit 423ecb
 * @filename: a filename or an URL
Packit 423ecb
 *
Packit 423ecb
 * Parse the resource and free the resulting tree
Packit 423ecb
 */
Packit 423ecb
static void
Packit 423ecb
example1Func(const char *filename) {
Packit 423ecb
    xmlDocPtr doc; /* the resulting document tree */
Packit 423ecb
Packit 423ecb
    doc = xmlReadFile(filename, NULL, 0);
Packit 423ecb
    if (doc == NULL) {
Packit 423ecb
        fprintf(stderr, "Failed to parse %s\n", filename);
Packit 423ecb
	return;
Packit 423ecb
    }
Packit 423ecb
    xmlFreeDoc(doc);
Packit 423ecb
}
Packit 423ecb
Packit 423ecb
int main(int argc, char **argv) {
Packit 423ecb
    if (argc != 2)
Packit 423ecb
        return(1);
Packit 423ecb
Packit 423ecb
    /*
Packit 423ecb
     * this initialize the library and check potential ABI mismatches
Packit 423ecb
     * between the version it was compiled for and the actual shared
Packit 423ecb
     * library used.
Packit 423ecb
     */
Packit 423ecb
    LIBXML_TEST_VERSION
Packit 423ecb
Packit 423ecb
    example1Func(argv[1]);
Packit 423ecb
Packit 423ecb
    /*
Packit 423ecb
     * Cleanup function for the XML library.
Packit 423ecb
     */
Packit 423ecb
    xmlCleanupParser();
Packit 423ecb
    /*
Packit 423ecb
     * this is to debug memory for regression tests
Packit 423ecb
     */
Packit 423ecb
    xmlMemoryDump();
Packit 423ecb
    return(0);
Packit 423ecb
}