Skip to content

Instantly share code, notes, and snippets.

Created Jan 29, 2010
What would you like to do?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <libxml/parser.h>
#include <libxml/HTMLparser.h>
#include <libxml/HTMLtree.h>
int main(int argc, char *argv[]) {
const char * htmldoc = "<html><body></body></html>";
const char * p_tag = "<p>hello world!</p>";
htmlDocPtr doc = htmlReadMemory(htmldoc, strlen(htmldoc), NULL, NULL,
xmlNodePtr root = xmlDocGetRootElement(doc);
xmlNodePtr body = root->children;
assert(strcmp("body", body->name) == 0);
xmlNodePtr list;
xmlParserErrors result = xmlParseInNodeContext(body, p_tag, strlen(p_tag),
0, &list);
assert(result == XML_ERR_OK);
printf("tag name: %s\n", list->name); // Shouldn't this be "p" ?
printf("doc pointer? %d\n", list == root); // It's not the root
// These seem to be completely unrelated documents.
htmlNodeDumpFile(stdout, doc, root);
htmlNodeDumpFile(stdout, doc, list);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment