blob: d62d0a53879523547f9a988e67183bd9ab516d78 [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) {
10
11 cur = cur->xmlChildrenNode;
12 while (cur != NULL) {
13 if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) {
14 printf("keyword: %s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
15 }
16 cur = cur->next;
17 }
18 return;
19}
20
21static void
22parseDoc(char *docname) {
23
24 xmlDocPtr doc;
25 xmlNodePtr cur;
26
27 doc = xmlParseFile(docname);
28
29 if (doc == NULL ) {
30 fprintf(stderr,"Document not parsed successfully. \n");
John Fleckbe98b332002-09-04 03:16:23 +000031 xmlFreeDoc(doc);
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +000032 return;
33 }
34
35 cur = xmlDocGetRootElement(doc);
36
37 if (cur == NULL) {
38 fprintf(stderr,"empty document\n");
39 xmlFreeDoc(doc);
40 return;
41 }
42
43 if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
44 fprintf(stderr,"document of the wrong type, root node != story");
45 xmlFreeDoc(doc);
46 return;
47 }
48
49 cur = cur->xmlChildrenNode;
50 while (cur != NULL) {
51 if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){
52 parseStory (doc, cur);
53 }
54
55 cur = cur->next;
56 }
MDT 2002 John Fleck77e4d352002-09-01 01:37:11 +000057
58 xmlFreeDoc(doc);
59 return;
MDT 2002 John Fleck598f6eb2002-06-04 15:10:36 +000060}
61
62int
63main(int argc, char **argv) {
64
65 char *docname;
66
67 if (argc <= 1) {
68 printf("Usage: %s docname\n", argv[0]);
69 return(0);
70 }
71
72 docname = argv[1];
73 parseDoc (docname);
74
75 return (1);
76}
77]]>