VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.30/doc/examples/parse3.c@ 20364

最後變更 在這個檔案從20364是 6076,由 vboxsync 提交於 17 年 前

Merged dmik/s2 branch (r25959:26751) to the trunk.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Date Revision Author Id
檔案大小: 1.5 KB
 
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}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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