|
1 | 1 | # ********************************************************************************************************* |
2 | | -# BuildingSync®, Copyright (c) 2015-2021, Alliance for Sustainable Energy, LLC, and other contributors. |
| 2 | +# BuildingSync®, Copyright (c) 2015-2025, Alliance for Sustainable Energy, LLC, and other contributors. |
3 | 3 | # |
4 | 4 | # All rights reserved. |
5 | 5 | # |
|
46 | 46 |
|
47 | 47 | GBXML_XSD_PATH = 'gbxml.xsd' |
48 | 48 | GBXML_IMPORT_PATH = 'xs:schema/xs:import[@namespace = "http://www.gbxml.org/schema"]' |
49 | | - if !File.file?(GBXML_XSD_PATH) then |
| 49 | + if !File.file?(GBXML_XSD_PATH) || File.size(GBXML_XSD_PATH) == 0 then |
50 | 50 | imported_schema_locations = schema_doc.xpath(GBXML_IMPORT_PATH).collect { |nokogiri_xml_node| |
51 | 51 | nokogiri_xml_node.attribute("schemaLocation").value |
52 | 52 | } |
53 | 53 | expect(imported_schema_locations.length).to eq 1 |
54 | 54 |
|
55 | | - open(GBXML_XSD_PATH, 'wb') do |file| |
56 | | - file << open(imported_schema_locations[0]).read |
| 55 | + begin |
| 56 | + puts "Downloading gbXML schema from: #{imported_schema_locations[0]}" |
| 57 | + File.open(GBXML_XSD_PATH, 'wb') do |file| |
| 58 | + file << URI.open(imported_schema_locations[0]).read |
| 59 | + end |
| 60 | + |
| 61 | + # Verify the downloaded file is valid XML |
| 62 | + if File.size(GBXML_XSD_PATH) == 0 |
| 63 | + raise "Downloaded file is empty" |
| 64 | + end |
| 65 | + |
| 66 | + # Test parse the downloaded XSD to ensure it's valid |
| 67 | + Nokogiri::XML(File.read(GBXML_XSD_PATH)) do |config| |
| 68 | + config.strict |
| 69 | + end |
| 70 | + puts "Successfully downloaded and validated gbXML schema" |
| 71 | + rescue => e |
| 72 | + puts "Failed to download gbXML schema: #{e.message}" |
| 73 | + # Clean up empty or invalid file |
| 74 | + File.delete(GBXML_XSD_PATH) if File.exist?(GBXML_XSD_PATH) |
| 75 | + raise "Could not download valid gbXML schema from #{imported_schema_locations[0]}: #{e.message}" |
57 | 76 | end |
58 | 77 | end |
59 | 78 | schema_doc.xpath(GBXML_IMPORT_PATH).collect { |nokogiri_xml_node| |
|
0 commit comments