From:
<glu...@gm...> - 2008-01-30 07:05:30
|
Hi Balazs! First: You don't have DTD in your xml. libxml++ can read it from your xml, or from an another file: <?xml version="1.0"?> <!DOCTYPE settings SYSTEM "myxml.dtd"> You can't validate your xml with the DomParser without a correct DTD. Second: You need catch the exceptions. Something like this: try { conf->load_general_settings("general.xml"); } catch (xmlpp::internal_error& ex) { Gtk::MessageDialog dlg(_("Internal error in the xml parser!"),false, Gtk::MESSAGE_ERROR,Gtk::BUTTONS_OK); dlg.set_secondary_text(ex.what()); dlg.run(); return -1; } catch (xmlpp::validity_error& ex) { ... } catch (xmlpp::exception& ex) { Gtk::MessageDialog dlg(_("Error in the xml parser!"),false, Gtk::MESSAGE_ERROR,Gtk::BUTTONS_OK); dlg.set_secondary_text(ex.what()); dlg.run(); return -1; } In this program I should not work with the bad xml, but sometimes it possible. In this case you need only a try-catch block in your code at the read, and it will work fine. But don't forget send a message to the user. Much easier to correct the bug in the xml, if you know, it is there. If you have problem with the validation, you can switch it of, and force the reading. Something like this: void read_from_xml(const char* file, bool validation=true) { xmlpp::DomParser parser; parser.set_validate(validation); parser.parse_file(file); ... } try { read_from_xml("myxml.xml"); } catch (xmlpp::validity_error& ex) { log.add_warning("myxml validation failed!"); read_from_xml("myxml.xml",false); } Attila |