Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created February 15, 2010 01:10
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/304365 to your computer and use it in GitHub Desktop.
Save tenderlove/304365 to your computer and use it in GitHub Desktop.
#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