VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.30/doc/tutorial/includegetattribute.c@ 7931

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

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

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Date Revision Author Id
檔案大小: 1.1 KB
 
1<![CDATA[
2#include <stdio.h>
3#include <string.h>
4#include <stdlib.h>
5#include <libxml/xmlmemory.h>
6#include <libxml/parser.h>
7
8void
9getReference (xmlDocPtr doc, xmlNodePtr cur) {
10
11 xmlChar *uri;
12 cur = cur->xmlChildrenNode;
13 while (cur != NULL) {
14 if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) {
15 uri = xmlGetProp(cur, "uri");
16 printf("uri: %s\n", uri);
17 xmlFree(uri);
18 }
19 cur = cur->next;
20 }
21 return;
22}
23
24
25void
26parseDoc(char *docname) {
27
28 xmlDocPtr doc;
29 xmlNodePtr cur;
30
31 doc = xmlParseFile(docname);
32
33 if (doc == NULL ) {
34 fprintf(stderr,"Document not parsed successfully. \n");
35 return;
36 }
37
38 cur = xmlDocGetRootElement(doc);
39
40 if (cur == NULL) {
41 fprintf(stderr,"empty document\n");
42 xmlFreeDoc(doc);
43 return;
44 }
45
46 if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
47 fprintf(stderr,"document of the wrong type, root node != story");
48 xmlFreeDoc(doc);
49 return;
50 }
51
52 getReference (doc, cur);
53 xmlFreeDoc(doc);
54 return;
55}
56
57int
58main(int argc, char **argv) {
59
60 char *docname;
61
62 if (argc <= 1) {
63 printf("Usage: %s docname\n", argv[0]);
64 return(0);
65 }
66
67 docname = argv[1];
68 parseDoc (docname);
69
70 return (1);
71}
72]]>
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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