- 论坛徽章:
- 0
|
请说的详细一点!
#include <stdio.h>;
#include <string.h>;
#include <stdlib.h>;
#include <libxml/xmlmemory.h>;
#include <libxml/parser.h>;
void
parseStory (xmlDocPtr doc, xmlNodePtr cur) {
xmlChar *key;
cur = cur->;xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->;name, (const xmlChar *)"keyword"))) {
key = xmlNodeListGetString(doc, cur->;xmlChildrenNode, 1);
printf("keyword: %s\n", key);
xmlFree(key);
}
cur = cur->;next;
}
return;
}
static void
parseDoc(char *docname) {
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(docname);
if (doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
return;
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return;
}
if (xmlStrcmp(cur->;name, (const xmlChar *) "story")) {
fprintf(stderr,"document of the wrong type, root node != story");
xmlFreeDoc(doc);
return;
}
cur = cur->;xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->;name, (const xmlChar *)"storyinfo"))){
parseStory (doc, cur);
}
cur = cur->;next;
}
xmlFreeDoc(doc);
return;
}
int
main(int argc, char **argv) {
char *docname;
if (argc <= 1) {
printf("Usage: %s docname\n", argv[0]);
return(0);
}
docname = argv[1];
parseDoc (docname);
return (1);
}
我这里有个例子,但是编译总是不成功,出现好多错误!错误如下:请大家帮忙找一下:
parse.c:4:30: libxml/xmlmemory.h: No such file or directory
parse.c:5:27: libxml/parser.h: No such file or directory
parse.c:8: parse error before "doc"
parse.c: In function `parseStory':
parse.c:10: `xmlChar' undeclared (first use in this function)
parse.c:10: (Each undeclared identifier is reported only once
parse.c:10: for each function it appears in.)
parse.c:10: `key' undeclared (first use in this function)
parse.c:11: `cur' undeclared (first use in this function)
parse.c:13: parse error before "xmlChar"
parse.c: At top level:
parse.c:20: parse error before "return"
parse.c: In function `parseDoc':
parse.c:26: `xmlDocPtr' undeclared (first use in this function)
parse.c:26: parse error before "doc"
parse.c:27: `xmlNodePtr' undeclared (first use in this function)
parse.c:29: `doc' undeclared (first use in this function)
parse.c:36: `cur' undeclared (first use in this function)
parse.c:44: parse error before "xmlChar"
parse.c: At top level:
parse.c:50: `cur' used prior to declaration
parse.c:50: invalid type argument of `->;'
parse.c:50: warning: data definition has no type or storage class
parse.c:51: parse error before "while"
parse.c:56: redefinition of `cur'
parse.c:50: `cur' previously defined here
parse.c:56: invalid type argument of `->;'
parse.c:56: warning: data definition has no type or storage class
parse.c:57: parse error before '}' token
parse.c:59: warning: parameter names (without types) in function declaration
parse.c:59: warning: data definition has no type or storage class
parse.c:60: parse error before "return"
parse.c:77:2: warning: no newline at end of file |
|