Sha256: 47ef502332d476147a5b4f595cfc2612233d98f63aebd874a156ae0e9cdd650a

Contents?: true

Size: 750 Bytes

Versions: 3

Compression:

Stored size: 750 Bytes

Contents

class XmlValidator
  require 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
  require 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

  include System::Xml
  include System::Xml::Schema

  def self.validate(xml_file, xsd_file)
    xml = File.read(xml_file)

    settings = XmlReaderSettings.new
    settings.validation_type = ValidationType.Schema;
    settings.schemas.add(nil, xsd_file)

    is_valid = true
    settings.validation_event_handler { |s, e|
      is_valid = false if e.severity == XmlSeverityType.error
    }

    reader = XmlReader.create(System::IO::StringReader.new(xml), settings)
    while reader.read
    end

    return is_valid
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
albacore-0.2.5 spec/support/ironruby_validator.rb
albacore-0.2.4 spec/support/ironruby_validator.rb
albacore-0.2.3 spec/support/ironruby_validator.rb