FeaturesPluginsDocs & SupportCommunityPartners

XML Schema Tools: Applying Design Patterns to XML Schema Files

Back to Getting Started With XML Schema Tools

The goal of this tutorial is to apply different design patterns to an XML schema file. You can use XML schema tools to apply one of the following design patterns to an XML schema file:

  • Venetian Blind. In the Venetian Blind design, there is a single global element; all other elements are local. Element declarations are nested within a single global declaration, using named complex types and element groups. Complex types and element groups can be reused throughout the schema. Only the root element must be defined within the global namespace.
  • Russian Doll. In the Russian Doll design, there is a single global element; all other elements are local. Element declarations are nested within a single global declaration and element declarations can only be used once. Only the root element must be defined within the global namespace.
  • Salami Slice. In the Salami Slice design, all elements are global. There is no nesting of element declarations and element declarations can be reused throughout the schema. All elements must be defined within the global namespace.
  • Garden of Eden. The Garden of Eden design is a combination of the Venetian Blind and Salami Slice designs. All elements and types are defined in the global namespace with the elements referenced as needed.

For more information about design patterns, see Introducing Design Patterns in XML Schemas.

Note: Wherever you see the icon, you can click to view a detailed interactive demonstration of the steps described in the tutorial.

top


Adding the Purchase Order Sample XML Schema

In this tutorial, you will use the Purchase Order sample XML schema that is bundled with the IDE.

To add a sample XML schema to the mySchemaPrj project:

  1. In the Projects window, if the mySchemaPrj project node is not expanded, expand it now.
  2. Expand the Source Packages node, select the <default package> node, right-click and choose New > File/Folder.
    The New File wizard opens. The Project drop-down list contains the name of the project where you are adding the file, in this case, mySchemaPrj.
  3. In the Categories list, expand the XML node and select the Sample Schemas node.
  4. In the File Types list, select Purchase Order Schema and click Next.
  5. Accept the default values in the Name and Location page of the wizard (File Name: newpo, Folder: src) and click Finish.
    In the Projects window, the <default package> node under the Source Packages node now contains a subnode labeled newpo.xsd. The newly created subnode is selected and the Source Editor contains a tab for the XML schema file, newpo.xsd.

 View Demo

top


Applying a Design Pattern

You can use the Design Pattern wizard to quickly determine which pattern is currently applied to the schema and select a new pattern to apply.

To apply a design pattern to an XML schema file:

  1. In the Projects window, expand the mySchemaPrj project node, the Source Packages node, and the <default package> node.
  2. Select the newpo.xsd file node.
  3. If the Navigator window is not open, from the IDE main menu, choose Window > Navigator.
  4. In the Navigator window, from the view drop-down list, select Design View.
    Notice that there are two global elements and three global complex types in the current version of the schema file.

    Elements before new design pattern

  5. In the Projects window, right-click the newpo.xsd file node and choose Apply Design Pattern from the pop-up menu.
    The Apply Design Pattern dialog box opens. Notice the warning message at the bottom of the dialog box that informs you that the selected design pattern is the same as the current design pattern, which is Garden of Eden.

    Selected pattern matches current pattern

  6. Under Global Element, select the Create a Single Global Element radio button and under Type, select the Do not Create Type(s) radio button.
    This defines Russian Doll as the design pattern to apply to the schema file. Notice that the Example box shows you an example of the design pattern.

    Selected Russian Doll pattern

  7. Click Finish.
    The IDE applies the new design pattern to the newpo XML schema file.
  8. In the Projects window, select the newpo.xsd file node and in the Navigator window, from the view drop-down list, select Design View.
    In the Russian Doll design pattern, there is a single global element. Notice that since the IDE applied the Russian Doll pattern, there is only one global element, purchaseOrder.

    Russian Doll applied, review change in Navigator window

 View Demo

top


Next Step

The last tutorial in this series, Validating XML Schemas, shows you how to use XML schema tools to validate your XML schema files.



top


Bookmark this page

del.icio.us furl simpy slashdot technorati digg
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Open ESB - The Open Enterprise Service Bus Powered by