module NoaaWeatherClient::Responses::ValidatableXmlResponse
Constants
- SCHEMA_PATH
Public Instance Methods
validate!(doc, schema_name)
click to toggle source
# File lib/noaa_weather_client/responses/validatable_xml_response.rb, line 8 def validate!(doc, schema_name) # chdir to help Nokogiri load included schemas Dir.chdir(SCHEMA_PATH) do schema_file = File.join(SCHEMA_PATH, "#{schema_name}.xsd") schema = Nokogiri::XML::Schema(File.read(schema_file)) errors = schema.validate(doc) unless errors.empty? raise Errors::InvalidXmlError, "Invalid xml: #{errors.map(&:message).join("\n")}" end end end