1 /**
2 * section: Parsing
3 * synopsis: Parse an XML document in memory to a tree and free it
4 * purpose: Demonstrate the use of xmlReadMemory() to read an XML file
5 * into a tree and xmlFreeDoc() to free the resulting tree
6 * usage: parse3
7 * test: parse3
8 * author: Daniel Veillard
9 * copy: see Copyright for the status of this software.
10 */
11
12 #include <stdio.h>
13 #include <libxml/parser.h>
14 #include <libxml/tree.h>
15
16 static const char *document = "<doc/>";
17
18 /**
19 * example3Func:
20 * @content: the content of the document
21 * @length: the length in bytes
22 *
23 * Parse the in memory document and free the resulting tree
24 */
25 static void
example3Func(const char * content,int length)26 example3Func(const char *content, int length) {
27 xmlDocPtr doc; /* the resulting document tree */
28
29 /*
30 * The document being in memory, it have no base per RFC 2396,
31 * and the "noname.xml" argument will serve as its base.
32 */
33 doc = xmlReadMemory(content, length, "noname.xml", NULL, 0);
34 if (doc == NULL) {
35 fprintf(stderr, "Failed to parse document\n");
36 return;
37 }
38 xmlFreeDoc(doc);
39 }
40
main(void)41 int main(void) {
42 /*
43 * this initialize the library and check potential ABI mismatches
44 * between the version it was compiled for and the actual shared
45 * library used.
46 */
47 LIBXML_TEST_VERSION
48
49 example3Func(document, 6);
50
51 /*
52 * Cleanup function for the XML library.
53 */
54 xmlCleanupParser();
55 /*
56 * this is to debug memory for regression tests
57 */
58 xmlMemoryDump();
59 return(0);
60 }
61