Friday, March 11, 2011

Externalize complex types for Web Service

It is a good programming practise to externalize re-usable complex types or elements in a separate XSD. This can be achived by using standard XML features.

XML provides a way to import any XSD in another XSD file. Now you can use those complex types or elements from imported XSD, but one thing is that you have to specify imported xsd file in a separated namespace and use the namespace prefix to use the complex type or element.

Suppose i have a XSD file, named base.xsd. In which i have a complex type:


Another xsd file in which AddressBn complex type will be used:


Steps:
1. specify namespace for the imported xsd as shown in the first highlighted text.

2. import the xsd file, with target namespace and schema location attribute as shown in the second highlighted text.

3. use the complex type or element prefix with namespace as shown in the third highlighted text.

No comments:

Post a Comment