Skip to content

Instantly share code, notes, and snippets.

@flavorjones
Created May 17, 2009 02:45
Show Gist options
  • Save flavorjones/112897 to your computer and use it in GitHub Desktop.
Save flavorjones/112897 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p>foo</p>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
</head>
<body>
<p>foo</p>
</body>
</html>
#include <stdio.h>
#include <libxml/xpath.h>
#include <libxml/xmlsave.h>
#include <libxml/HTMLparser.h>
#include <libxml/HTMLtree.h>
int io_write_callback(void * context, const char * buffer, int len) { }
int main(int argc, char**argv)
{
printf("parsing %s\n", argv[1]);
htmlDocPtr doc = htmlReadFile((const char *)argv[1], NULL, 0);
xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc);
xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression("//meta", xpathCtx);
xmlNodePtr node = xpathObj->nodesetval->nodeTab[0];
xmlSaveCtxtPtr savectx = xmlSaveToIO(io_write_callback, NULL, NULL, NULL, 0);
xmlSaveTree(savectx, node);
xmlSaveClose(savectx);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment