VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.30/doc/tutorial/includeaddkeyword.c@ 11632

Last change on this file since 11632 was 6076, checked in by vboxsync, 17 years ago

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

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 1.3 KB
Line 
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
9parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) {
10
11 xmlNewTextChild (cur, NULL, "keyword", keyword);
12 return;
13}
14
15xmlDocPtr
16parseDoc(char *docname, char *keyword) {
17
18 xmlDocPtr doc;
19 xmlNodePtr cur;
20
21 doc = xmlParseFile(docname);
22
23 if (doc == NULL ) {
24 fprintf(stderr,"Document not parsed successfully. \n");
25 return (NULL);
26 }
27
28 cur = xmlDocGetRootElement(doc);
29
30 if (cur == NULL) {
31 fprintf(stderr,"empty document\n");
32 xmlFreeDoc(doc);
33 return (NULL);
34 }
35
36 if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
37 fprintf(stderr,"document of the wrong type, root node != story");
38 xmlFreeDoc(doc);
39 return (NULL);
40 }
41
42 cur = cur->xmlChildrenNode;
43 while (cur != NULL) {
44 if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){
45 parseStory (doc, cur, keyword);
46 }
47
48 cur = cur->next;
49 }
50 return(doc);
51}
52
53int
54main(int argc, char **argv) {
55
56 char *docname;
57 char *keyword;
58 xmlDocPtr doc;
59
60 if (argc <= 2) {
61 printf("Usage: %s docname, keyword\n", argv[0]);
62 return(0);
63 }
64
65 docname = argv[1];
66 keyword = argv[2];
67 doc = parseDoc (docname, keyword);
68 if (doc != NULL) {
69 xmlSaveFormatFile (docname, doc, 0);
70 xmlFreeDoc(doc);
71 }
72
73 return (1);
74}
75]]>
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