12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #include <stdio.h>
- #include <libxml/parser.h>
- #include <libxml/tree.h>
- #ifdef LIBXML_TREE_ENABLED
- static void
- print_element_names(xmlNode * a_node)
- {
- xmlNode *cur_node = NULL;
- for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
- if (cur_node->type == XML_ELEMENT_NODE) {
- printf("node type: Element, name: %s\n", cur_node->name);
- }
- print_element_names(cur_node->children);
- }
- }
- int
- main(int argc, char **argv)
- {
- xmlDoc *doc = NULL;
- xmlNode *root_element = NULL;
- if (argc != 2)
- return(1);
-
- LIBXML_TEST_VERSION
-
- doc = xmlReadFile(argv[1], NULL, 0);
- if (doc == NULL) {
- printf("error: could not parse file %s\n", argv[1]);
- }
-
- root_element = xmlDocGetRootElement(doc);
- print_element_names(root_element);
-
- xmlFreeDoc(doc);
-
- xmlCleanupParser();
- return 0;
- }
- #else
- int main(void) {
- fprintf(stderr, "Tree support not compiled in\n");
- exit(1);
- }
- #endif
|