FUSE Services Framework supports the including and importing of schema definitions, using the
<include/>
and <import/>
schema tags. These tags enable you to
insert definitions from external files or resources into the scope of a schema element. The essential difference between including
and importing is:
Including brings in definitions that belong to the same target namespace as the enclosing schema element.
Importing brings in definitions that belong to a different target namespace from the enclosing schema element.
The include directive has the following syntax:
<include schemaLocation="anyURI
" />
The referenced schema, given by anyURI
, must either belong to the same target namespace
as the enclosing schema, or not belong to any target namespace at all. If the referenced schema does not belong to any target
namespace, it is automatically adopted into the enclosing schema’s namespace when it is included.
Example 10.1 shows an example of an XML Schema document that includes another XML Schema document.
Example 10.1. Example of a Schema that Includes Another Schema
<definitions targetNamespace="http://schemas.fusesource.com/tests/schema_parser" xmlns:tns="http://schemas.fusesource.com/tests/schema_parser" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <schema targetNamespace="http://schemas.fusesource.com/tests/schema_parser" xmlns="http://www.w3.org/2001/XMLSchema"> <include schemaLocation="included.xsd"/> <complexType name="IncludingSequence"> <sequence> <element name="includedSeq" type="tns:IncludedSequence"/> </sequence> </complexType> </schema> </types> ... </definitions>
Example 10.2 shows the contents of the included schema file.
Example 10.2. Example of an Included Schema
<schema targetNamespace="http://schemas.fusesource.com/tests/schema_parser" xmlns="http://www.w3.org/2001/XMLSchema"> <!-- Included type definitions --> <complexType name="IncludedSequence"> <sequence> <element name="varInt" type="int"/> <element name="varString" type="string"/> </sequence> </complexType> </schema>
The import directive has the following syntax:
<import namespace="namespaceAnyURI
" schemaLocation="schemaAnyURI
" />
The imported definitions must belong to the namespaceAnyURI target
namespace. If namespaceAnyURI
is blank or remains unspecified, the imported schema definitions are unqualified.
Example 10.3 shows an example of an XML Schema that imports another XML Schema.
Example 10.3. Example of a Schema that Includes Another Schema
<definitions targetNamespace="http://schemas.fusesource.com/tests/schema_parser" xmlns:tns="http://schemas.fusesource.com/tests/schema_parser" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <schema targetNamespace="http://schemas.fusesource.com/tests/schema_parser" xmlns="http://www.w3.org/2001/XMLSchema"> <import namespace="http://schemas.fusesource.com/tests/imported_types" schemaLocation="included.xsd"/> <complexType name="IncludingSequence"> <sequence> <element name="includedSeq" type="tns:IncludedSequence"/> </sequence> </complexType> </schema> </types> ... </definitions>
Example 10.4 shows the contents of the imported schema file.
Example 10.4. Example of an Included Schema
<schema targetNamespace="http://schemas.fusesource.com/tests/imported_types" xmlns="http://www.w3.org/2001/XMLSchema"> <!-- Included type definitions --> <complexType name="IncludedSequence"> <sequence> <element name="varInt" type="int"/> <element name="varString" type="string"/> </sequence> </complexType> </schema>
Using types defined in a schema document that is not referenced in the service's WSDL document is a three step process:
Convert the schema document to a WSDL document using the xsd2wsdl tool.
Generate Java for the types using the wsdl2java tool on the generated WSDL document.
![]() | Important |
---|---|
You will get a warning from the wsdl2java tool stating that the WSDL document does not define any services. You can ignore this warning. |
Add the generated classes to your classpath.