Created
February 15, 2010 01:10
-
-
Save tenderlove/304365 to your computer and use it in GitHub Desktop.
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 <libxml/parser.h> | |
#include <libxml/xmlsave.h> | |
#include <libxml/HTMLparser.h> | |
#include <libxml/HTMLtree.h> | |
static int writer(void * ctxt, const char * buf, int len) | |
{ | |
printf("%s", buf); | |
return len; | |
} | |
static int closer(void * ctxt) { return 0; } | |
int main(int argc, char *argv[]) { | |
const char *html = "<html><head><style>\n" \ | |
"<![CDATA[\n" \ | |
"body { background-color:#ffffff; }\n" \ | |
"]]>\n" \ | |
"</style></head><body></body></html>"; | |
htmlDocPtr doc = htmlReadMemory(html, strlen(html), NULL, "UTF-8", 0); | |
/* Save as HTML */ | |
xmlSaveCtxtPtr savectx = xmlSaveToIO( | |
writer, | |
closer, | |
NULL, | |
"UTF-8", | |
XML_SAVE_AS_HTML); | |
xmlSaveDoc(savectx, doc); | |
xmlSaveClose(savectx); | |
printf("\n\n\n"); | |
/* Save as XHTML */ | |
savectx = xmlSaveToIO( | |
writer, | |
closer, | |
NULL, | |
"UTF-8", | |
XML_SAVE_XHTML); | |
xmlSaveDoc(savectx, doc); | |
xmlSaveClose(savectx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment