Skip to main content
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : XML : Education - Tutorials
XML Schema Infoset Model, Part 1
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
6. Working with namespaces

Includes page 2 of 3

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

//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

Main menuSection menuFeedbackPreviousNext
About IBM | Privacy | Legal | Contact