CYCLUS
Loading...
Searching...
No Matches
relax_ng_validator.cc
Go to the documentation of this file.
1/* relaxngvalidator.cpp
2 * this class is agented off of the schemavalidator in libxml++
3 * here is their license statement:
4 *
5 * libxml++ and this file are copyright (C) 2000 by Ari Johnson,
6 * (C) 2002-2004 by the libxml dev team and
7 * are covered by the GNU Lesser General Public License, which should be
8 * included with libxml++ as the file COPYING.
9 */
10
11#include "relax_ng_validator.h"
12
13#include <libxml/xmlerror.h>
14#include <libxml/relaxng.h>
15#include <libxml++/document.h>
16
17#include "error.h"
18
19namespace cyclus {
20
21// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22RelaxNGValidator::RelaxNGValidator() : schema_(0), valid_context_(0) {}
23
24// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28
29// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31 release_underlying(); // Free any existing info
32 schema_ = xmlRelaxNGParse(context);
33 if (!schema_) {
34 throw ValidationError("Schema could not be parsed");
35 }
36}
37
38// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39void RelaxNGValidator::parse_memory(const Glib::ustring& contents) {
42 parse_context(context);
43}
44
45// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57
58// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59bool RelaxNGValidator::Validate(const xmlpp::Document* doc) {
60 if (!doc) {
61 throw ValidationError("Document pointer cannot be 0");
62 }
63
64 if (!schema_) {
65 throw ValidationError("Must have a schema to validate document");
66 }
67
68 // A context is required at this stage only
69 if (!valid_context_) {
71 }
72
73 if (!valid_context_) {
74 throw ValidationError("Couldn't create validating context");
75 }
76
77 int res;
78 try {
80 } catch (xmlError e) {
81 throw ValidationError(e.message);
82 }
83
84 if (res != 0) {
85 throw ValidationError("Document failed schema validation");
86 }
87
88 return res;
89}
90
91} // namespace cyclus
void release_underlying()
free xml-related memory
void parse_memory(const Glib::ustring &contents)
parse a relaxng schema xml file
xmlRelaxNG * schema_
the schema
void parse_context(xmlRelaxNGParserCtxt *context)
parse a relaxng schema context
xmlRelaxNGValidCtxt * valid_context_
the validated context
bool Validate(const xmlpp::Document *doc)
validate an xml file agaisnt the given schema
For validating files received via IO.
Definition error.h:71
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters