環境は
VisualC++2005ExpressEdition
http://www.zlatkovic.com/pub/libxml/
こちらからWindows用バイナリをDL
今のバージョンは libxml2-2.6.32+.win32.zip
C/C++ 追加のインクルードディレクトリに libxml2/include を追加
リンカ 追加のライブラリディレクトリに libxml2/lib を追加
こんなRSSを
< ?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<copyright>Copyright 2007-2008, ...</copyright>
snip..
こんな感じでパースできる
#include <libxml /xmlmemory.h> #include </libxml> <libxml /parser.h>
int XMLParser::parse( string filename ) {
xmlDocPtr doc = xmlParseFile( filename.c_str() );
if (doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
return 0;
}
xmlNodePtr cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return 0;
}
if (xmlStrcmp(cur->name, (const xmlChar *) "rss")) {
fprintf(stderr,"document of the wrong type, root node != rss");
xmlFreeDoc(doc);
return 0;
}
xmlChar *version = xmlGetProp(cur, (const xmlChar *)"version");
printf("version: %s\n", version); // "2.0"
xmlFree(version);
xmlFreeDoc(doc);
return 1;
}
めんどくさい