Skip to content

Commit

Permalink
#5319 - Catch version of schema from gbXML root element, and issue a …
Browse files Browse the repository at this point in the history
…clearer warning
  • Loading branch information
jmarrec committed Dec 18, 2024
1 parent 5bc916e commit d01e567
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/gbxml/ReverseTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,29 @@ namespace gbxml {

if (openstudio::filesystem::exists(path)) {

// validate the gbxml prior to reverse translation
auto gbxmlValidator = XMLValidator::gbxmlValidator();
gbxmlValidator.validate(path);

openstudio::filesystem::ifstream file(path, std::ios_base::binary);
if (file.is_open()) {
pugi::xml_document doc;
auto load_result = doc.load(file);
if (load_result) {
result = this->convert(doc.document_element());
auto root = doc.document_element();
if (std::string_view{root.name()} != "gbXML") {
LOG(Error, "Expected the root element to be <gbXML>");
return boost::none;
}
// Scan version of gbxml schema
std::string version = root.attribute("version").value();
if (version.empty()) {
LOG(Warn, "gbXML has no `version` attribute for the schema version, assuming 7.03.");
version = "7.03";
} else if (version != "7.03") {
LOG(Error, "Version of schema specified: " << version << ", expected 7.03. Validation will still assume 7.03, expect errors.");
}
// validate the gbxml prior to reverse translation
auto gbxmlValidator = XMLValidator::gbxmlValidator();
gbxmlValidator.validate(path);

result = this->convert(root);
}
file.close();
}
Expand Down

0 comments on commit d01e567

Please sign in to comment.