Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created January 29, 2010 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/289553 to your computer and use it in GitHub Desktop.
Save tenderlove/289553 to your computer and use it in GitHub Desktop.
#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,
HTML_PARSE_RECOVER);
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);
printf("\n");
htmlNodeDumpFile(stdout, doc, list);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment