An XML Schema model may contain any number of
<xsd:include> elements.
Their schemaLocation attributes consist of a
URI reference that should be relative to the root XML
Schema model document.
The XML Schema corresponding to the root XML Schema
contains not only the components corresponding to its
definition and declaration, but also all the components
of all the XML Schemas corresponding to any
<xsd:include>d schema documents.
Such included schema documents must either:
- Have the same targetNamespace as the
<xsd:include>ing schema document
- Have no targetNamespace at all, in which case the
<xsd:include>d schema document is
converted to the <xsd:include>ing schema
document's targetNamespace.
The code snippet below shows how you would create and add
a <xsd:include> to a root schema. As soon as the
xsdSchema.getContents().add(0,xsdInclude) method is
called you will notice that the included schema will get
loaded into the same resource set that the root schema
is in.
//Create a XSDInclude
XSDInclude xsdInclude = XSDFactory.eINSTANCE.createXSDInclude();
//Set the uri to the xml schema file that you want to use the definitions from
xsdInclude.setSchemaLocation("address.xsd");
//we always add the new includes to the top of the root schemas content list
//the included XML Schema file will be loaded at this time
xsdSchema.getContents().add(0,xsdInclude);