The printing to stderr is done by
libxml2, not by libxml++. It was not as easy as I thought to find
out how to avoid it, and the solution I found is somewhat bizarre.
The libxml2 function initGenericErrorDefaultFunc() takes a pointer to a function pointer. #include <libxml++/libxml++.h> #include <libxml/xmlerror.h> #include <iostream> #include <stdlib.h> using namespace std; using namespace xmlpp; static void myGenericErrorFunc(void* /* parsing context */, const char* /* format (like fprintf) */, ...) { // Don't print anything. // libxml2's default GenericErrorFunc prints to stderr. } static xmlGenericErrorFunc pGenericErrorFunc = myGenericErrorFunc; int main() { initGenericErrorDefaultFunc(&pGenericErrorFunc); try { xmlpp::DomParser parser; parser.set_throw_messages(true); parser.parse_file("config.xml"); } catch (const xmlpp::exception& ex) { cout << ex.what() << endl; } return 0; } 2013-07-30 23:12, Pablo Madoery skrev:
|