XML Schema Design Patterns
XML Schema Design Patterns
Design Patterns
1
Popular XML Schema Design
Patterns
Russian Doll
Salami Slice
Venetian Blind
Garden of Eden
2
Popular XML Schema Design
Patterns
The patterns vary according to the
number of their global elements or
types.
You can conveniently classify the four
most common patterns according to
two criteria, namely:
Ease of use for instance developers
Ease of reuse for schema developers
3
Russian Doll
4
Russian Doll
5
Example: Russian Doll
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.sun.com/point/russiandoll"
xmlns:tns="http://schemas.sun.com/point/russiandoll"
elementFormDefault="qualified">
Advantages
Contains only one valid root element.
Could reduce the complexity of
namespace
Easy to use from instance developer's
point of view
Disadvantages
Reuse of elements is limited – not easy to
use from schema developer's point of
view
Supports single-file schema only
7
Usage
8
Salami Slide
9
Salami Slice
10
Example: Salami Slide
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.sun.com/point/salami"
xmlns:tns="http://schemas.sun.com/point/salami"
xmlns="http://schemas.sun.com/point/salami"
elementFormDefault="qualified">
<xsd:element name="PointB">
<xsd:complexType>
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="Line">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="PointA"/>
<xsd:element ref="PointB"/>
</xsd:sequence> 11
Advantages & Disadvantages
Advantages
Contains all reusable elements.
Supports reuse of elements from other
documents.
Disadvantages
Exposes the complexity in namespace.
12
Venetian Blind
13
Venetian Blind
<xsd:complexType name="PointType">
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
15
Advantages & Disadvantages
Advantages
Contains only one single root element.
Allows reuse for all the types and the
single global element.
Allows multiple files
Disadvantages
Limits encapsulation by exposing types.
16
Usage
17
Garden of Eden
18
Garden of Eden
19
Example: Garden of Eden
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.sun.com/point/gardenofeden"
xmlns="http://schemas.sun.com/point/gardenofeden"
elementFormDefault="qualified">
<xsd:complexType name="PointType">
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
<xsd:complexType name="LineType">
<xsd:sequence>
<xsd:element ref="PointA"/>
<xsd:element ref="PointB"/>
</xsd:sequence>
</xsd:complexType>
Global elements
<xsd:element name="PointA" type="PointType"/>
Advantages
Allows reuse of both elements and types.
Allows multiple files.
Disadvantages
Contains many potential root elements.
Limits encapsulation by exposing types.
Is difficult to read and understand.
21
NetBeans Support
on XML Schema
Design Patterns
22
NetBeans XML Schema Design
Support
Lets you choose a design pattern by
letting you choose
Scheme of Creating global element
Scheme of Creating type
Creating type
Create Type(s)
Do not Create Type(s)
23
NetBeans XML Schema Design
Support
24
XML Schema
Design Patterns
25