I'm using this program to display a list of all html tags in a given file:
#include <cstdio>
#include <libxml/HTMLparser.h>
#include <libxml/tree.h>
#include <iostream>
#include <cstring>
using namespace std;
static void
print_element_names(htmlNodePtr a_node)
{
htmlNodePtr cur_node = NULL;
for (cur_node = a_node; cur_node!=NULL; cur_node = cur_node->next) {
printf("node type: Element, name: %s\n", cur_node->name);
print_element_names(cur_node->children);
}
}
int main(int argc, char **argv) {
htmlDocPtr doc;
htmlNodePtr root_node;
doc = htmlReadFile(argv[1], NULL, 0);
root_node = xmlDocGetRootElement(doc);
print_element_names(root_node);
xmlFreeDoc(doc);
xmlCleanupParser();
return 0;
}
How do I get it to display the attributes as well (eg. href="something" for )?