An XML Schema model may contain any number of
<xsd:import>
elements.
Their schemaLocation attributes consist of a
URI reference that should be relative to the root XML
Schema document. Unlike <xsd:include>,
<xsd:import> has a namespace attribute that needs
to match a namespace in the QName prefix namespace map.
The <xsd:import> element tag identifies namespaces
used in external references, in other words, those whose QNames
identify them as coming from a different namespace than
the root schema document's targetNamespace. The actual
value of its namespace indicates that the containing
schema document may contain qualified references to
schema components in that namespace (via one or more
prefixes declared with namespace declarations in the
normal way).
The code snippet below shows how you would create and add
a <xsd:import> to a root schema document. As soon
as the xsdSchema.getContents().add(0,xsdImport) method
is called, you might notice that the imported schema
might NOT
get loaded. To force the load on a <xsd:import>
you need to call
((XSDImportImpl)xsdImport).importSchema();.
//Create a XSDImport
XSDImport xsdImport = XSDFactory.eINSTANCE.createXSDImport();
//Set the uri to the xml schema file that you want to use the definitions from
xsdImport.setSchemaLocation("address.xsd");
//we always add the new imports to the top of the root schemas content list
xsdSchema.getContents().add(0,xsdImport);
//This will force load the imported schema
((XSDImportImpl)xsdImport).importSchema();