次の方法で共有


Schema Design Patterns: Venetian Blind

This is the third of five entries talking about schema design patterns.  In previous entries the Russian Doll approach and the Salami Slice approach were discussed.

The Venetian Blind approach is similar to the Russian Doll approach in that they both use a single global element.  The Venetian Blind approach describes a modular approach by naming and defining all type definitions globally (as opposed to the Salami Slice approach which declares elements globally and types locally).  Each globally defined type describes an individual "slat" and can be reused by other components.  In addition, all the locally declared elements can be namespace qualified or namespace unqualified (the slats can be "opened" or "closed") depending on the elementFormDefault attribute setting at the top of the schema.  If the namespace is unqualified then the local elements in the instance document must not be qualified with the prefix of the namespace.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="TargetNamespace" xmlns:TN="TargetNamespace" xmlns:xs="https://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="BookInformation" type="TN:BookInformation" maxOccurs="unbounded"/>
    <xs:complexType name="BookInformation">
        <xs:sequence>
            <xs:element name="Title"/>
            <xs:element name="ISBN"/>
            <xs:element name="PeopleInvolved" type="TN:PeopleInvolvedType" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="PeopleInvolvedType">
        <xs:sequence>
            <xs:element name="Author"/>
            <xs:element name="Publisher"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

 

The advantages are that since all complex and simple types are defined globally they are available for reuse.  In addition, the option exists to hide the namespace prefix for all locally defined elements in the instance document.

The disadvantages are that the schema is verbose, it is not self contained and it may be coupled with other schemas.

This type of approach is good when flexibility, reuse and namespace exposure are important.  This approach uses a combination of local and global types unlike the Russian Doll approach which all components are locally declared and the Salami Slice where all components are globally declared.  This is important as it provides the flexibility to create a schema for most needs since the types can be assigned to elements and extended or restricted as needed.  This would be an appropriate design when data is transferred between diverse organizations or business units since it provides each group the flexibility for modifications for each specific requirement.

Comments