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 www.w3schools.com/xml/el_import.asp

Constant Summary

Constants inherited from BaseObject

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

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#id, #options

Instance Method Summary collapse

Methods inherited from BaseObject

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

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

#namespaceObject

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_locationObject

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_schemaObject

Get imported schema

Returns:

  • Schema



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

def imported_schema
  known_schemas = reader.schemas_for_namespace(namespace)
  return known_schemas.first if known_schemas.any?

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

  xml = reader.resource_resolver.call(schema_location, namespace)
  new_schema = reader.add_schema_xml(xml)

  unless namespace == new_schema.target_namespace
    raise ImportError, 'Import namespace does not match imported schema targetNamespace'
  end

  new_schema
end