[libxml++] Improve the DtdValidation and SchemaValidation example programs.
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml++] Improve the DtdValidation and SchemaValidation example programs.
- Date: Thu, 9 Aug 2012 08:53:53 +0000 (UTC)
commit 348aa558a008fd66cf65d260110ed459eb388a67
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Thu Aug 9 10:47:14 2012 +0200
Improve the DtdValidation and SchemaValidation example programs.
* examples/dtdvalidation/main.cc:
* examples/schemavalidation/main.cc: Print all information from all thrown
xmlpp exceptions.
ChangeLog | 8 ++++++++
examples/dtdvalidation/main.cc | 12 +++++++-----
examples/schemavalidation/main.cc | 17 +++++++++++------
3 files changed, 26 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ed58e7c..c3a08c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2012-08-09 Kjell Ahlstedt <kjell ahlstedt bredband net>
+ Improve the DtdValidation and SchemaValidation example programs.
+
+ * examples/dtdvalidation/main.cc:
+ * examples/schemavalidation/main.cc: Print all information from all thrown
+ xmlpp exceptions.
+
+2012-08-09 Kjell Ahlstedt <kjell ahlstedt bredband net>
+
Validators: Improve the error handling.
* libxml++/validators/validator.[h|cc]:
diff --git a/examples/dtdvalidation/main.cc b/examples/dtdvalidation/main.cc
index b235b14..1e2f613 100644
--- a/examples/dtdvalidation/main.cc
+++ b/examples/dtdvalidation/main.cc
@@ -54,9 +54,10 @@ int main(int argc, char* argv[])
std::cerr << "Validation successful (not expected)" << std::endl;
return_code = EXIT_FAILURE;
}
- catch( const xmlpp::validity_error& )
+ catch (const xmlpp::exception& ex)
{
std::cout << "Error validating the document (expected)" << std::endl;
+ std::cout << ex.what() << std::endl;
}
/* xmlpp::Element* nodeRoot2 = */document.create_root_node("example");
@@ -66,19 +67,20 @@ int main(int argc, char* argv[])
try
{
- xmlpp::DtdValidator validator2( dtdfilepath );
- validator2.validate( &document );
+ validator.validate( &document );
std::cout << "Validation successful" << std::endl;
}
- catch( const xmlpp::validity_error& )
+ catch (const xmlpp::exception& ex)
{
std::cerr << "Error validating the document" << std::endl;
+ std::cerr << ex.what() << std::endl;
return_code = EXIT_FAILURE;
}
}
- catch( const xmlpp::parse_error& )
+ catch (const xmlpp::exception& ex)
{
std::cerr << "Error parsing the dtd" << std::endl;
+ std::cerr << ex.what() << std::endl;
return_code = EXIT_FAILURE;
}
return return_code;
diff --git a/examples/schemavalidation/main.cc b/examples/schemavalidation/main.cc
index 1c5d38a..1857bd1 100644
--- a/examples/schemavalidation/main.cc
+++ b/examples/schemavalidation/main.cc
@@ -51,24 +51,29 @@ int main(int argc, char* argv[])
try
{
- xmlpp::DomParser parser(docfilepath);
xmlpp::SchemaValidator validator(schemafilepath);
+ Glib::ustring phase;
try
{
+ phase = "parsing";
+ xmlpp::DomParser parser(docfilepath);
+
+ phase = "validating";
validator.validate( parser.get_document() );
std::cout << "Valid document" << std::endl;
}
- catch( const xmlpp::validity_error& error)
+ catch (const xmlpp::exception& ex)
{
- std::cerr << "Error validating the document" << std::endl;
- std::cerr << error.what();
+ std::cerr << "Error " << phase << " the document" << std::endl;
+ std::cerr << ex.what() << std::endl;
return EXIT_FAILURE;
}
}
- catch( const xmlpp::parse_error& error)
+ catch (const xmlpp::exception& ex)
{
- std::cerr << "Error parsing the schema: " << error.what() << std::endl;
+ std::cerr << "Error parsing the schema" << std::endl;
+ std::cerr << ex.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]