3 * synopsis: Parse and validate an XML file to a tree and free the result
4 * purpose: Create a parser context for an XML file, then parse and validate
5 * the file, creating a tree, check the validation result
6 * and xmlFreeDoc() to free the resulting tree.
7 * usage: parse2 test2.xml
8 * test: parse2 test2.xml
9 * author: Daniel Veillard
10 * copy: see Copyright for the status of this software.
14 #include <libxml/parser.h>
15 #include <libxml/tree.h>
19 * @filename: a filename or an URL
21 * Parse and validate the resource and free the resulting tree
24 exampleFunc(const char *filename) {
25 xmlParserCtxtPtr ctxt; /* the parser context */
26 xmlDocPtr doc; /* the resulting document tree */
28 /* create a parser context */
29 ctxt = xmlNewParserCtxt();
31 fprintf(stderr, "Failed to allocate parser context\n");
34 /* parse the file, activating the DTD validation option */
35 doc = xmlCtxtReadFile(ctxt, filename, NULL, XML_PARSE_DTDVALID);
36 /* check if parsing suceeded */
38 fprintf(stderr, "Failed to parse %s\n", filename);
40 /* check if validation suceeded */
42 fprintf(stderr, "Failed to validate %s\n", filename);
43 /* free up the resulting document */
46 /* free up the parser context */
47 xmlFreeParserCtxt(ctxt);
50 int main(int argc, char **argv) {
55 * this initialize the library and check potential ABI mismatches
56 * between the version it was compiled for and the actual shared
64 * Cleanup function for the XML library.
68 * this is to debug memory for regression tests