Class: Lutaml::Xml::SchemaLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/schema_location.rb

Overview

SchemaLocation manages xsi:schemaLocation attribute which provides schema validation hints as namespace-location pairs

Uses W3C XmlSchema-instance namespace (xsi) for the schemaLocation attribute itself. Each location pair associates a namespace (via XmlNamespace class) with its schema URL.

Examples:

Creating a schema location

class MyNs < Lutaml::Xml::W3c::XmlNamespace
  uri "http://example.com/ns"
end

schema_loc = SchemaLocation.new(
  locations: {
    MyNs => "http://example.com/schema.xsd"
  }
)

With custom xsi prefix

schema_loc = SchemaLocation.new(
  locations: { MyNs => "http://example.com/schema.xsd" },
  xsi_prefix: "xmlschema-instance"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locations:, xsi_prefix: "xsi") ⇒ SchemaLocation

Returns a new instance of SchemaLocation.

Parameters:

  • locations (Hash{Class => String}, Array<Location>)

    namespace class to location mapping or Location array

  • xsi_prefix (String) (defaults to: "xsi")

    prefix for XMLSchema-instance namespace (default: “xsi”)



84
85
86
87
# File 'lib/lutaml/xml/schema_location.rb', line 84

def initialize(locations:, xsi_prefix: "xsi")
  @schema_location = build_locations(locations)
  @xsi_prefix = xsi_prefix
end

Instance Attribute Details

#schema_locationObject (readonly)

Returns the value of attribute schema_location.



80
81
82
# File 'lib/lutaml/xml/schema_location.rb', line 80

def schema_location
  @schema_location
end

#xsi_prefixObject (readonly)

Returns the value of attribute xsi_prefix.



80
81
82
# File 'lib/lutaml/xml/schema_location.rb', line 80

def xsi_prefix
  @xsi_prefix
end

Instance Method Details

#[](index) ⇒ Object



110
111
112
# File 'lib/lutaml/xml/schema_location.rb', line 110

def [](index)
  @schema_location[index]
end

#sizeObject



114
115
116
# File 'lib/lutaml/xml/schema_location.rb', line 114

def size
  @schema_location.size
end

#to_xml_attributesHash{String => String}

Generate XML attributes for schema location declaration

Returns:

  • (Hash{String => String})

    xmlns and schemaLocation attributes



103
104
105
106
107
108
# File 'lib/lutaml/xml/schema_location.rb', line 103

def to_xml_attributes
  {
    "xmlns:#{xsi_prefix}" => xsi_namespace,
    "#{xsi_prefix}:schemaLocation" => schema_location.map(&:to_xml_attribute).join(" "),
  }
end

#xsi_namespaceString

Returns the XMLSchema-instance namespace URI

Returns:

  • (String)


97
98
99
# File 'lib/lutaml/xml/schema_location.rb', line 97

def xsi_namespace
  xsi_namespace_class.uri
end

#xsi_namespace_classClass

Returns the XMLSchema-instance namespace class

Returns:

  • (Class)

    Xml::W3c::XsiNamespace



91
92
93
# File 'lib/lutaml/xml/schema_location.rb', line 91

def xsi_namespace_class
  Lutaml::Xml::W3c::XsiNamespace
end