1 /* xml++.h 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. 6 */ 7 8 #ifndef __LIBXMLPP_VALIDATORS_DTDVALIDATOR_H 9 #define __LIBXMLPP_VALIDATORS_DTDVALIDATOR_H 10 11 #include <libxml++/validators/validator.h> 12 #include <libxml++/dtd.h> 13 #include <libxml++/document.h> 14 15 namespace xmlpp { 16 17 /** XML DTD validator. 18 */ 19 class DtdValidator : public Validator 20 { 21 public: 22 DtdValidator(); 23 24 /** Create a validator and parse an external subset (DTD file) immediately. 25 * @param file The URL of the DTD. 26 * @throws xmlpp::parse_error 27 */ 28 explicit DtdValidator(const Glib::ustring& file); 29 30 /** Create a validator and parse an external subset (DTD file) immediately. 31 * @param external The external ID of the DTD. 32 * @param system The URL of the DTD. 33 * @throws xmlpp::parse_error 34 */ 35 explicit DtdValidator(const Glib::ustring& external,const Glib::ustring& system); 36 37 ~DtdValidator() override; 38 39 //TODO: Remove virtuals when we can break ABI, 40 //or really put these in the base class. 41 42 /** Parse an external subset (DTD file). 43 * If the validator already contains a DTD, that DTD is deleted. 44 * @param external The external ID of the DTD. 45 * @param system The URL of the DTD. 46 * @throws xmlpp::parse_error 47 */ 48 virtual void parse_subset(const Glib::ustring& external,const Glib::ustring& system); 49 50 /** Parse an external subset (DTD file). 51 * If the validator already contains a DTD, that DTD is deleted. 52 * @param filename The URL of the DTD. 53 * @throws xmlpp::parse_error 54 */ 55 virtual void parse_file(const Glib::ustring& filename); 56 57 /** Parse a DTD from a string. 58 * If the validator already contains a DTD, that DTD is deleted. 59 * @param contents The DTD as a string. 60 * @throws xmlpp::parse_error 61 */ 62 virtual void parse_memory(const Glib::ustring& contents); 63 64 /** Parse a DTD from a stream. 65 * If the validator already contains a DTD, that DTD is deleted. 66 * @param in The stream. 67 * @throws xmlpp::parse_error 68 */ 69 virtual void parse_stream(std::istream& in); 70 71 /** Test whether a DTD has been parsed. 72 */ 73 operator bool() const; 74 75 /** Get the parsed DTD. 76 * @returns A pointer to the parsed DTD, or <tt>nullptr</tt>. 77 */ 78 Dtd* get_dtd(); 79 80 /** Get the parsed DTD. 81 * @returns A pointer to the parsed DTD, or <tt>nullptr</tt>. 82 */ 83 const Dtd* get_dtd() const; 84 85 /** Validate a document, using a previously parsed DTD. 86 * The internal subset (if present) is de-coupled (i.e. not used), 87 * which could give problems if ID or IDREF is present. 88 * @param doc Pointer to the document. 89 * @returns Whether the document is valid. 90 * @throws xmlpp::internal_error 91 * @throws xmlpp::validity_error 92 */ 93 bool validate(const Document* doc); 94 95 protected: 96 void release_underlying() override; 97 98 Dtd* dtd_; 99 }; 100 101 } // namespace xmlpp 102 103 #endif //__LIBXMLPP_VALIDATORS_DTDVALIDATOR_H 104 105