MDT 2002 John Fleck | 598f6eb | 2002-06-04 15:10:36 +0000 | [diff] [blame] | 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 | |
| 8 | void |
| 9 | parseStory (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 | |
| 21 | static void |
| 22 | parseDoc(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"); |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | cur = xmlDocGetRootElement(doc); |
| 35 | |
| 36 | if (cur == NULL) { |
| 37 | fprintf(stderr,"empty document\n"); |
| 38 | xmlFreeDoc(doc); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | if (xmlStrcmp(cur->name, (const xmlChar *) "story")) { |
| 43 | fprintf(stderr,"document of the wrong type, root node != story"); |
| 44 | xmlFreeDoc(doc); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | cur = cur->xmlChildrenNode; |
| 49 | while (cur != NULL) { |
| 50 | if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){ |
| 51 | parseStory (doc, cur); |
| 52 | } |
| 53 | |
| 54 | cur = cur->next; |
| 55 | } |
MDT 2002 John Fleck | 77e4d35 | 2002-09-01 01:37:11 +0000 | [diff] [blame^] | 56 | |
| 57 | xmlFreeDoc(doc); |
| 58 | return; |
MDT 2002 John Fleck | 598f6eb | 2002-06-04 15:10:36 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | int |
| 62 | main(int argc, char **argv) { |
| 63 | |
| 64 | char *docname; |
| 65 | |
| 66 | if (argc <= 1) { |
| 67 | printf("Usage: %s docname\n", argv[0]); |
| 68 | return(0); |
| 69 | } |
| 70 | |
| 71 | docname = argv[1]; |
| 72 | parseDoc (docname); |
| 73 | |
| 74 | return (1); |
| 75 | } |
| 76 | ]]> |