正如nwellnhof所建议的,可以通过设置错误处理程序来避免连接错误。尤其是结构化错误处理程序。
而
the answer
#include <stdio.h>
#include <libxml/parser.h>
void structuredErrorFunc(void *userData, xmlErrorPtr error) {
printf("xmlStructuredErrorFunc\n");
}
void genericErrorFunc(void *ctx, const char * msg, ...) {
printf("xmlGenericErrorFunc\n");
}
int main(void) {
xmlDocPtr doc;
xmlChar *s;
xmlSetGenericErrorFunc(NULL, genericErrorFunc);
xmlSetStructuredErrorFunc(NULL, structuredErrorFunc);
doc = xmlParseFile("http://localhost:8000/sitemap.xml");
s = xmlNodeGetContent((struct _xmlNode *)doc);
printf("%s\n", s);
return 0;
}
这个输出,
xmlStructuredErrorFunc
<result of xmlNodeGetContent>