Just DO IT by luckygxf // // Created by gxf on 2020/2/6. // #include <stdio.h> #include <string.h> #include <libxml/parser.h> //#include <libxml/tree.h> void println(char *s); typedef struct { char *name; char *author; char *date; }book; void printBook(book book1); int main() { xmlDocPtr bookDocPtr; xmlNodePtr booksNodePtr; char *bookDocName = “/Users/gxf/CLionProjects/untitled/books.xml”; // libxml默认将各个节点间的空格当作一个节点 xmlKeepBlanksDefault(0); bookDocPtr = xmlParseFile(bookDocName); if (bookDocPtr == NULL) { fprintf(stderr, “xmlReadFile fail”); exit(1); } book onebook; // root node booksNodePtr = xmlDocGetRootElement(bookDocPtr); // book node xmlNodePtr bookNodePtr = booksNodePtr->children; while (bookNodePtr) { // name xmlNodePtr namePtr = bookNodePtr->children; // println(xmlNodeGetContent(namePtr)); onebook.name = xmlNodeGetContent(namePtr); // author xmlNodePtr authorPtr = namePtr->next; // println(xmlNodeGetContent(authorPtr)); onebook.author = xmlNodeGetContent(authorPtr); // date xmlNodePtr datePtr = authorPtr->next; // println(xmlNodeGetContent(datePtr)); onebook.date = xmlNodeGetContent(datePtr); printBook(onebook); bookNodePtr = bookNodePtr->next; } return 0; } void println(char *s) { printf(“%s ”, s); } void printBook(book book1) { printf(“name: %s ”, book1.name); printf(“author: %s ”, book1.author); printf(“date: %s ”, book1.date); }
2024最新激活全家桶教程,稳定运行到2099年,请移步至置顶文章:https://sigusoft.com/99576.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。 文章由激活谷谷主-小谷整理,转载请注明出处:https://sigusoft.com/84824.html