VirtualBox

source: vbox/trunk/src/libs/libxml2-2.9.2/doc/examples/parse3.c@ 58072

Last change on this file since 58072 was 58072, checked in by vboxsync, 9 years ago

libxml 2.9.2 unmodified

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
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 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
16static 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 */
25static void
26example3Func(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
41int 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}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette