Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <libxml/parser.h>
- int main(int argc, char *argv[]) {
- const char *filename = argv[1];
- xmlDocPtr doc;
- xmlNodePtr root, node;
- // return "file handle" to read the file
- doc = xmlParseFile(filename);
- if (doc == NULL) {
- fprintf(stderr, "Unable to parse data\n");
- xmlFreeDoc(doc);
- exit (1);
- } else {
- puts("Data parsed successfully");
- }
- // return pointer to the root element
- root = xmlDocGetRootElement(doc);
- if (root == NULL) {
- fprintf(stderr, "Can't read data\n");
- xmlFreeDoc(doc);
- exit (1);
- } else {
- printf("Root node is '%s'\n", root->name);
- }
- if (root->children) {
- printf("Child nodes:\n");
- for (node = root->children; node; node = node->next) {
- if (node->type == XML_ELEMENT_NODE) {
- printf("\t%s\n", node->name);
- }
- }
- }
- xmlFreeDoc(doc);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement