Created
January 29, 2010 08:13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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