1 /* Copyright (C) 2014 The libxml++ development team
3 * This file is part of libxml++.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 * This file was adapted from schemavalidator.h by Fugro Intersite B.V./Tjalling Hattink
21 #ifndef __LIBXMLPP_VALIDATOR_RELAXNGVALIDATOR_H
22 #define __LIBXMLPP_VALIDATOR_RELAXNGVALIDATOR_H
24 #include <libxml++/validators/schemavalidatorbase.h>
25 #include <memory> // std::auto_ptr
29 class LIBXMLPP_API ustring;
34 class LIBXMLPP_API Document;
35 class LIBXMLPP_API RelaxNGSchema;
37 /** RelaxNG schema validator.
38 * RelaxNG = REgular LAnguage for XML Next Generation
42 class LIBXMLPP_API RelaxNGValidator : public SchemaValidatorBase
47 /** Create a validator and parse a schema definition file.
48 * The schema must be defined with XML syntax (.rng file). The compact syntax
49 * (.rnc file) is not supported.
50 * @param filename The URL of the schema.
51 * @throws xmlpp::parse_error
53 explicit RelaxNGValidator(const Glib::ustring& filename);
55 /** Create a validator and parse a schema definition document.
56 * @param document A preparsed document tree, containing the schema definition.
57 * @throws xmlpp::parse_error
59 explicit RelaxNGValidator(const Document* document);
61 /** Create a validator.
62 * @param schema A pointer to the schema to use when validating XML documents.
63 * @param take_ownership If <tt>true</tt>, the validator takes ownership of
64 * the schema. The caller must not delete it.<br>
65 * If <tt>false</tt>, the validator does not take ownership of the schema.
66 * The caller must guarantee that the schema exists as long as the
67 * validator keeps a pointer to it. The caller is responsible for
68 * deleting the schema when it's no longer needed.
70 explicit RelaxNGValidator(RelaxNGSchema* schema, bool take_ownership);
72 ~RelaxNGValidator() override;
74 //TODO: Remove virtuals when we can break ABI,
75 //or really put these in the base class.
77 /** Parse a schema definition file.
78 * The schema must be defined with XML syntax (.rng file). The compact syntax
79 * (.rnc file) is not supported.
81 * If the validator already contains a schema, that schema is released
82 * (deleted if the validator owns the schema).
83 * @param filename The URL of the schema.
84 * @throws xmlpp::parse_error
86 void parse_file(const Glib::ustring& filename) override;
88 /** Parse a schema definition from a string.
89 * The schema must be defined with XML syntax. The compact syntax is not supported.
91 * If the validator already contains a schema, that schema is released
92 * (deleted if the validator owns the schema).
93 * @param contents The schema definition as a string.
94 * @throws xmlpp::parse_error
96 void parse_memory(const Glib::ustring& contents) override;
98 /** Parse a schema definition from a document.
99 * If the validator already contains a schema, that schema is released
100 * (deleted if the validator owns the schema).
101 * @param document A preparsed document tree, containing the schema definition.
102 * @throws xmlpp::parse_error
104 void parse_document(const Document* document) override;
107 * If the validator already contains a schema, that schema is released
108 * (deleted if the validator owns the schema).
109 * @param schema A pointer to the schema to use when validating XML documents.
110 * @param take_ownership If <tt>true</tt>, the validator takes ownership of
111 * the schema. The caller must not delete it.<br>
112 * If <tt>false</tt>, the validator does not take ownership of the schema.
113 * The caller must guarantee that the schema exists as long as the
114 * validator keeps a pointer to it. The caller is responsible for
115 * deleting the schema when it's no longer needed.
117 void set_schema(RelaxNGSchema* schema, bool take_ownership);
119 /** Test whether a schema has been parsed.
122 * if (relaxng_validator)
126 operator BoolExpr() const override;
129 * @returns A pointer to the schema, or <tt>nullptr</tt>.
131 RelaxNGSchema* get_schema();
134 * @returns A pointer to the schema, or <tt>nullptr</tt>.
136 const RelaxNGSchema* get_schema() const;
138 /** Validate a document, using a previously parsed schema.
139 * @param document Pointer to the document.
140 * @throws xmlpp::internal_error
141 * @throws xmlpp::validity_error
143 void validate(const Document* document) override;
145 /** Validate an XML file, using a previously parsed schema.
146 * @param filename The URL of the XML file.
147 * @throws xmlpp::internal_error
148 * @throws xmlpp::parse_error
149 * @throws xmlpp::validity_error
151 void validate(const Glib::ustring& filename) override;
154 void initialize_valid() override;
155 void release_underlying() override;
159 std::auto_ptr<Impl> pimpl_;
164 #endif //__LIBXMLPP_VALIDATOR_RELAXNGVALIDATOR_H