dinsdag 6 oktober 2009

The things every IT Professional should know about XML Schema design Part 2

Last time I wrote about the namespace design and its versioning issues. Today I will write about the difference between the <xsd:import> and the <xsd:include> statement.


Import versus include

There is a major difference between the include and the import statement originating from the design of the XML schema.

The <xsd:import> statement was introduced to use components from a schema file with its own namespace in the current schema. Using the <xsd:import> statement in coorporation with xmlns:abc= attribute in the xsd:schema statement referencing the schema the components of the imported schema can be used by using the namespace token.




The <xsd:include> statement was introduced to combine multiple files which all have the same namespace. Its original design was to combine the files of one namespace which spanned multiple physical files. Splitting the namespace into multiple physical files can have advantages like performance advanages or clustering functional elements together in a file for better understanding.
One of the characteristics of the include sttement is that it hides the namespace. The components of the included schema can be used as if they are part of the targetNamespace. This can introduce problems when elements have the same name. And when using include the context of the original namespace is lost. So when having a namespace design which has a functional meaning this is an absolute no-go area.
 
Summarized
The Pros of import
- Explicit usage of components of other namesapces, which enables impact analysis for changes.
- Clear usage of components even when using the same name twice.
- Requires strict design of the schema

The Pros of include
- Enables splitting of files

The cons of import
- None

The cons of include
- Namespace is lost
- The includes are incorporated in a client side component into one phisical file. This deminishes the pro of the include in the usage scenari of XML schema in services.

Combining include and import
There are scenarios when a combination of the import and include statement are applicable. It is recommended when having large XML schema files to split them. This can be done by either splitting the files and only using thos files with the include statement or by reconsidering the namespace design. When the latter choice is chosen the need for include is absolutely zero.

Geen opmerkingen:

Een reactie posten