Re: [libxml++] parser problem



Hi!

First of all, I think you slightly misunderstood what i wrote.

1. I'm aware of that I don't have DTD in my xml. I have a very good reason for that. Namely, I don't need it. I'll do the validation with a schema and not with DTD. (I also know that libxml++ doesn't contain a wrapper to do that, but i've already applied Emilien KIA's patch, so now it is capable to do validation with schemas)

2. The problem is not with the validation (It does not even get there).
The problem is that the xml is _not_ well formed. And what I would like is to get the error somehow in my program, but instead it just writes error messages to the console. Of course I use exceptions as you wrote, and I catch everything at the end [catch (...)], but this error cannot be catched because - as i noticed - it doesn't raise an exception.

With the method I mentioned in my previous mail, I'm able to catch those error, but I thougth - maybe - there's a simplier way to do that.

I hope it's more clear now.

--
Balazs

----- Original Message -----
From: Glück Attila Béla <gluck attila bela gmail com>
To: libxmlplusplus-general lists sourceforge net
Sent: Wed, Jan 30, 2008 8:04:56 AM +0100
Subject: [libxml++] parser problem

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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Libxmlplusplus-general mailing list
Libxmlplusplus-general lists sourceforge net
https://lists.sourceforge.net/lists/listinfo/libxmlplusplus-general





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]