Class: XSD::Import

Inherits:
BaseObject show all
Defined in:
lib/xsd/objects/import.rb

Overview

The import element is used to add multiple schemas with different target namespace to a document. Parent elements: schema https://www.w3schools.com/xml/el_import.asp

Constant Summary

Constants inherited from BaseObject

BaseObject::NO_ATTRIBUTES_CONTAINER, BaseObject::NO_ELEMENTS_CONTAINER, BaseObject::XML_SCHEMA, BaseObject::XML_SCHEMA_NS

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#id, #options

Instance Method Summary collapse

Methods inherited from BaseObject

#[], child, #collect_attributes, #collect_elements, #documentation, #documentation_for, #get_prefix, #initialize, #inspect, link, #map_child, #map_children, mapped_name, #namespaces, #node, #node_to_object, #nodes, #object_by_name, #parent, property, #reader, #schema, #schemas_for_namespace, #strip_prefix, to_underscore

Constructor Details

This class inherits a constructor from XSD::BaseObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class XSD::BaseObject

Instance Attribute Details

#namespace ⇒ Object

Optional. Specifies the URI of the namespace to import

Returns:

  • String, nil



11
# File 'lib/xsd/objects/import.rb', line 11

property :namespace, :string

#schema_location ⇒ Object

Optional. Specifies the URI to the schema for the imported namespace

Returns:

  • String, nil



16
# File 'lib/xsd/objects/import.rb', line 16

property :schemaLocation, :string

Instance Method Details

#imported_schema ⇒ Object

Get imported schema

Returns:

  • Schema



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/xsd/objects/import.rb', line 20

def imported_schema
  # a schema for the namespace may already be known, either added manually or by another import
  known_schema = reader.schemas_for_namespace(namespace).find { |s| !s.equal?(schema) }
  return known_schema if known_schema

  unless schema_location
    raise ImportError,
          "Schema location not provided for namespace '#{namespace}', use add_schema_xml()/add_schema_node()"
  end

  new_schema = reader.load_schema(schema_location, namespace: namespace, base: schema.location)

  unless namespace == new_schema.target_namespace
    raise ImportError, "Import namespace '#{namespace}' does not match imported schema targetNamespace " \
                       "'#{new_schema.target_namespace}'"
  end

  new_schema
end