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_VALIDATORS_DTDVALIDATOR_H
9 #define __LIBXMLPP_VALIDATORS_DTDVALIDATOR_H
11 #include <libxml++/validators/validator.h>
12 #include <libxml++/dtd.h>
13 #include <libxml++/document.h>
17 /** XML DTD validator.
18 * DTD = Document Type Definition
20 class DtdValidator : public Validator
25 /** Create a validator and parse an external subset (DTD file) immediately.
26 * @param filename The URL of the DTD.
27 * @throws xmlpp::parse_error
29 explicit DtdValidator(const std::string& filename);
31 /** Create a validator and parse an external subset (DTD file) immediately.
32 * @param external The external ID of the DTD.
33 * @param system The URL of the DTD.
34 * @throws xmlpp::parse_error
36 explicit DtdValidator(const Glib::ustring& external, const Glib::ustring& system);
38 /** Create a validator.
42 * @param dtd A pointer to the DTD to use when validating XML documents.
43 * @param take_ownership If <tt>true</tt>, the validator takes ownership of
44 * the DTD. The caller must not delete it.<br>
45 * If <tt>false</tt>, the validator does not take ownership of the DTD.
46 * The caller must guarantee that the DTD exists as long as the
47 * validator keeps a pointer to it. The caller is responsible for
48 * deleting the DTD when it's no longer needed.
50 explicit DtdValidator(Dtd* dtd, bool take_ownership);
52 ~DtdValidator() override;
54 /** Parse an external subset (DTD file).
55 * If the validator already contains a DTD, that DTD is deleted.
56 * @param filename The URL of the DTD.
57 * @throws xmlpp::parse_error
59 void parse_file(const std::string& filename) override;
61 /** Parse an external subset (DTD file).
62 * If the validator already contains a DTD, that DTD is deleted.
63 * @param external The external ID of the DTD.
64 * @param system The URL of the DTD.
65 * @throws xmlpp::parse_error
67 void parse_subset(const Glib::ustring& external, const Glib::ustring& system);
69 /** Parse a DTD from a string.
70 * If the validator already contains a DTD, that DTD is deleted.
71 * @param contents The DTD as a string.
72 * @throws xmlpp::parse_error
74 void parse_memory(const Glib::ustring& contents) override;
76 /** Parse a DTD from a stream.
77 * If the validator already contains a DTD, that DTD is deleted.
78 * @param in The stream.
79 * @throws xmlpp::parse_error
81 void parse_stream(std::istream& in);
84 * If the validator already contains a DTD, that DTD is released
85 * (deleted if the validator owns the DTD).
86 * @param dtd A pointer to the DTD to use when validating XML documents.
87 * @param take_ownership If <tt>true</tt>, the validator takes ownership of
88 * the DTD. The caller must not delete it.<br>
89 * If <tt>false</tt>, the validator does not take ownership of the DTD.
90 * The caller must guarantee that the DTD exists as long as the
91 * validator keeps a pointer to it. The caller is responsible for
92 * deleting the DTD when it's no longer needed.
94 void set_dtd(Dtd* dtd, bool take_ownership);
96 /** Test whether a DTD has been parsed.
103 explicit operator bool() const noexcept override;
105 /** Get the parsed DTD.
106 * @returns A pointer to the parsed DTD, or <tt>nullptr</tt>.
110 /** Get the parsed DTD.
111 * @returns A pointer to the parsed DTD, or <tt>nullptr</tt>.
113 const Dtd* get_dtd() const;
115 /** Validate a document, using a previously parsed DTD.
116 * The internal subset (if present) is de-coupled (i.e. not used),
117 * which could give problems if ID or IDREF is present.
118 * @param document Pointer to the document.
119 * @throws xmlpp::internal_error
120 * @throws xmlpp::validity_error
122 void validate(const Document* document) override;
125 void initialize_context() override;
126 void release_underlying() override;
130 std::unique_ptr<Impl> pimpl_;
135 #endif //__LIBXMLPP_VALIDATORS_DTDVALIDATOR_H