#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#ifdef LIBXML_TREE_ENABLED
static void
print_tree(xmlNode * root_node)
{
xmlNode *cur_node = NULL;
for (cur_node = root_node; cur_node; cur_node = cur_node->next)
{
if (cur_node->type == XML_ELEMENT_NODE)
{
printf("<%s>\n", cur_node->name);
}
print_tree(cur_node->children);
}
}
int
main(int argc, char **argv)
{
xmlDoc *doc = NULL;
xmlNode *root_element = NULL;
if (argc != 2)
return(1);
doc = xmlReadFile(argv[1], NULL, 0);
if (doc == NULL )
{
printf("Document parsing failed!!! \n");
exit (1);
}
root_element = xmlDocGetRootElement(doc);
if (root_element == NULL)
{
printf("Document is empty\n");
xmlFreeDoc(doc);
exit(1);
}
print_tree(root_element);
xmlFreeDoc(doc);
xmlCleanupParser();
return 0;
}
#else
int main(void)
{
printf("Tree support not compiled in\n");
exit(1);
}
#endif
Master programming effortlessly with Simplest Codings. From core algorithms and LLMs to clean code in Java, C++, and Python—get clear, bite-sized tutorials and practical developer guides for all skill levels.
Wednesday, September 29, 2010
Traversing and Printing the XML Tree
This program traverses the nodes of the XML Document and prints them in the order.
Subscribe to:
Post Comments (Atom)
-
Overview of the SSL handshake Courtesy: http://www-01.ibm.com/support/knowledgecenter Steps involved in SSL handshake (Courtesy:...
-
To implement the kind of storage which stores strings as the search keys , there is a need to have special data structures which can store ...
-
A simple implementation of a packet sniffer in C on linux platform using the libpcap library. This packet sniffer currently sniffs IP , TCP ...
No comments:
Post a Comment
Please post your valuable suggestions