From 1f4c24eda0163e9da0b6801ef7f2ffdb287060e5 Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Wed, 18 Dec 2024 13:37:47 +0100 Subject: [PATCH] #5319 - Catch version of schema from gbXML root element, and issue a clearer warning --- src/gbxml/ReverseTranslator.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gbxml/ReverseTranslator.cpp b/src/gbxml/ReverseTranslator.cpp index f8f2126605b..7f1ab04ad08 100644 --- a/src/gbxml/ReverseTranslator.cpp +++ b/src/gbxml/ReverseTranslator.cpp @@ -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 "); + 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(); }