on 2010年9月17日星期五 | 0 评论

Russian Doll Design

This design approach has the schema structure mirror the instance document structure, e.g., declare a Book element and within it declare a Title element followed by an Author element:
<xsd:element name="Book"> 
        <xsd:complexType> 
            <xsd:sequence> 
                <xsd:element name="Title" type="xsd:string"/> 
                <xsd:element name="Author" type="xsd:string"/> 
            </xsd:sequence> 
        </xsd:complexType> 
    </element>
The instance document has all its components bundled together. Likewise, the schema is designed to bundle together all its element declarations. This design represents one end of the design spectrum.


Salami Slice Design

The Salami Slice design represents the other end of the design spectrum. With this design we disassemble the instance document into its individual components. In the schema we define each component (as an element declaration), and then assemble them together:
<xsd:element name="Title" type="xsd:string"/>

    <xsd:element name="Author" type="xsd:string"/>

    <xsd:element name="Book">
        <xsd:complexType> 
            <xsd:sequence> 
                <xsd:element ref="Title"/> 
                <xsd:element ref="Author"/>
            </xsd:sequence> 
        </xsd:complexType> 
</xsd:element>

Note how the schema declared each component individually (Title, and Author) and then assembled them together (by ref'ing them) in the creation of the Book component.
These two designs represent opposite ends of the design spectrum.
To understand these designs it may help to think in terms of boxes, where a box represents an element or type:
  • The Russian Doll design corresponds to having a single box, and it has nested within it boxes, which in turn have boxes nested within them, and so on. (boxes within boxes, just like a Russian Doll!)
  • The Salami Slice design corresponds to having many separate boxes which are assembled together (separate boxes combined together, just like Salami slices brought together in a sandwich!)

Venetian Blind Design

With this design approach we disassemble the problem into individual components, as the Salami Slice design does, but instead of creating element declarations, we create type definitions. Here's what our example looks like with this design approach:
<xsd:simpleType name="Title">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Mr."/> 
            <xsd:enumeration value="Mrs."/> 
            <xsd:enumeration value="Dr."/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="Name">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/> 
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="Publication">
        <xsd:sequence>
            <xsd:element name="Title" type="Title"/> 
            <xsd:element name="Author" type="Name"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="Book" type="Publication"/>
This design has:
  • maximized reuse (there are four reusable components - the Title type, the Name type, the Publication type, and the Book element)
  • maximized the potential to hide (localize) namespaces [note how this has been phrased: "maximized the potential ..." Whether, in fact, the namespaces of Title and Author are hidden or exposed, is determined by the elementFormDefault "switch"].
The Venetian Blind design espouses these guidelines ...
  • Design your schema to maximize the potential for hiding (localizing) namespace complexities.
  • Use elementFormDefault to act as a switch for controlling namespace exposure - if you want element namespaces exposed in instance documents, simply turn the elementFormDefault switch to "on" (i.e, set elementFormDefault= "qualified"); if you don't want element namespaces exposed in instance documents, simply turn the elementFormDefault switch to "off" (i.e., set elementFormDefault="unqualified").
  • Design your schema to maximize reuse.
  • Use type definitions as the main form of component reuse.
  • Nest element declarations within type definitions.
 Ref:http://www.xfront.com/GlobalVersusLocal.html



0 评论:

发表评论