Method: XSD::BaseObject#schemas_for_namespace

Defined in:
lib/xsd/base_object.rb

#schemas_for_namespace(ns_or_prefix) ⇒ Object

Get schemas by namespace or prefix

Parameters:

  • ns_or_prefix (String, nil)


78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/xsd/base_object.rb', line 78

def schemas_for_namespace(ns_or_prefix)
  # resolve namespace for current node if prefix was provided
  prefix = node.namespaces[['xmlns', (ns_or_prefix == '' ? nil : ns_or_prefix)].compact.join(':')]
  ns = prefix || ns_or_prefix

  if schema.targets_namespace?(ns)
    [schema, *schema.includes.map(&:imported_schema)]
  elsif (import = schema.import_by_namespace(ns))
    [import.imported_schema]
  else
    raise Error, "Schema not found for namespace '#{ns}' in '#{schema.id || schema.target_namespace}'"
  end
end