2 * libxml++ and this file are copyright (C) 2000 by Ari Johnson,
3 * (C) 2002-2004 by the libxml dev team and
4 * are covered by the GNU Lesser General Public License, which should be
5 * included with libxml++ as the file COPYING.
8 #ifndef __LIBXMLPP_VALIDATOR_H
9 #define __LIBXMLPP_VALIDATOR_H
11 #ifdef _MSC_VER //Ignore warnings about the Visual C++ Bug, where we can not do anything
12 #pragma warning (disable : 4786)
15 #include <libxml++/noncopyable.h>
16 #include <libxml++/exceptions/validity_error.h>
17 #include <libxml++/exceptions/internal_error.h>
18 #include <memory> // std::unique_ptr
29 /** Base class for XML validators.
31 class Validator : public NonCopyable
35 ~Validator() override;
37 /** Parse a schema definition file or an external subset (DTD file).
38 * @param filename The URL of the schema or the DTD.
39 * @throws xmlpp::parse_error
41 virtual void parse_file(const std::string& filename) = 0;
43 /** Parse a schema definition or a DTD from a string.
44 * @param contents The schema definition or the DTD as a string.
45 * @throws xmlpp::parse_error
47 virtual void parse_memory(const Glib::ustring& contents) = 0;
49 /** Validate a document, using a previously parsed schema or DTD.
50 * @param document Pointer to the document.
51 * @throws xmlpp::internal_error
52 * @throws xmlpp::validity_error
54 virtual void validate(const Document* document) = 0;
56 /** Test whether a schema or a DTD has been parsed.
63 explicit virtual operator bool() const noexcept = 0;
66 virtual void initialize_context();
67 virtual void release_underlying();
69 virtual void on_validity_error(const Glib::ustring& message);
70 virtual void on_validity_warning(const Glib::ustring& message);
72 /// To be called in an exception handler.
73 virtual void handle_exception();
74 virtual void check_for_exception();
75 virtual void check_for_validity_messages();
77 static void callback_validity_error(void* ctx, const char* msg, ...);
78 static void callback_validity_warning(void* ctx, const char* msg, ...);
80 std::unique_ptr<exception> exception_;
81 // Built gradually - used in an exception at the end of validation.
82 Glib::ustring validate_error_;
83 Glib::ustring validate_warning_;
88 #endif //__LIBXMLPP_VALIDATOR_H