libxml2 2.9.1 clean sources
[tomato.git] / release / src / router / libxml2 / doc / tutorial / includekeyword.c
blobe9bb4672474b72f924b10a045138ff6f9c7da77c
1 <![CDATA[
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <libxml/xmlmemory.h>
6 #include <libxml/parser.h>
8 void
9 parseStory (xmlDocPtr doc, xmlNodePtr cur) {
11 xmlChar *key;
12 cur = cur->xmlChildrenNode;
13 while (cur != NULL) {
14 if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) {
15 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
16 printf("keyword: %s\n", key);
17 xmlFree(key);
19 cur = cur->next;
21 return;
24 static void
25 parseDoc(char *docname) {
27 xmlDocPtr doc;
28 xmlNodePtr cur;
30 doc = xmlParseFile(docname);
32 if (doc == NULL ) {
33 fprintf(stderr,"Document not parsed successfully. \n");
34 return;
37 cur = xmlDocGetRootElement(doc);
39 if (cur == NULL) {
40 fprintf(stderr,"empty document\n");
41 xmlFreeDoc(doc);
42 return;
45 if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
46 fprintf(stderr,"document of the wrong type, root node != story");
47 xmlFreeDoc(doc);
48 return;
51 cur = cur->xmlChildrenNode;
52 while (cur != NULL) {
53 if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){
54 parseStory (doc, cur);
57 cur = cur->next;
60 xmlFreeDoc(doc);
61 return;
64 int
65 main(int argc, char **argv) {
67 char *docname;
69 if (argc <= 1) {
70 printf("Usage: %s docname\n", argv[0]);
71 return(0);
74 docname = argv[1];
75 parseDoc (docname);
77 return (1);
79 ]]>