Sha256: ad153092bd04f9f4c38fcbee0fa9ece5ec04d46ec85fc258ae017b11e4d59437

Contents?: true

Size: 764 Bytes

Versions: 1

Compression:

Stored size: 764 Bytes

Contents

# Helps to validate xml against schemas contained in a WSDL
class WsdlValidator
  # @param [String] wsdl_url URL to where WSDL is stored
  def initialize(wsdl_url)
    @doc = Wasabi.document wsdl_url
    @schemas = @doc.parser.schemas.collect(&:to_s).join
  end

  # @param [String, Nokogiri::XML::NodeSet] xml
  # @return [Boolean] Whether xml is valid according to WSDL of class
  def valid?(xml)
    raise "Incorrect type #{xml.class}" unless [String, Nokogiri::XML::Document, Nokogiri::XML::NodeSet].include? xml.class
    xml_under_test = Nokogiri::XML(xml.to_s)
    xsd = Nokogiri::XML::Schema(@schemas)
    validator = xsd.validate(xml_under_test)
    validator.each { |error| puts error.message }
    return false unless validator.empty?
    true
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wsdl_validator-0.1.2 lib/wsdl_validator/wsdl_validator.rb