Skip to content

Instantly share code, notes, and snippets.

@tenderlove tenderlove/test.c
Created Jan 29, 2010

Embed
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,
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
You can’t perform that action at this time.