blob: 975168d70a213e15cb66f96296b0f2d697e155c3 [file] [log] [blame]
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +00001<![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);
MDT 2002 John Fleck77e4d352002-09-01 01:37:11 +000070 xmlFreeDoc(doc);
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +000071 }
MDT 2002 John Fleck77e4d352002-09-01 01:37:11 +000072
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +000073 return (1);
74}
75]]>