Writing XML Schema using Salami Slice Approach

Hi,

An XML schema describes the valid form and content of a conforming XML document. It is not required that every XML document has a corresponding schema, but it is important to have if you actually want to have others consume your documents.

In plain words The schema is used to validate a document, and to assist people/programs from creating their own versions of XML according to the schema.

In this post I will discuss about one of heavily used pattern “Salami Slice”.

Salami Slice
This pattern represent the different style of design spectrum. This pattern lets you disassemble the instance of document into its individual components. In plain words it lets us to define each element separately and then assemble them together later.


Lets take an example of Product entity.

<!–?xml version=”1.0″ encoding=”UTF-8″?>
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema&#8221; elementFormDefault=”qualified” attributeFormDefault=”unqualified”>

<!– Define the Elements gloabally –>
<xs:element name=”ProductTitle” type=”xsd:string” minOccurs=”0″/>

<xs:element name=”ProductCode” type=”xsd:int” minOccurs=”0″ />

<xs:element name=”MinPrice” type=”xsd:string” minOccurs=”0″ />

<xs:element name=”MaxPrice” type=”xsd:string” minOccurs=”0″ />

<xs:element name=”ProductPriceRange”>
<xs:complexType>
<xs:sequence>
<xs:element ref=”MinPrice” minOccurs=”0″ />
<xs:element ref=”MaxPrice” minOccurs=”0″/>
</xs:sequence>
</xs:complexType>
</xs:element>

<!– Now Construct the Actual Product Element, by Using the ‘ref’ of above defined elements –>
<xs:element name=”Product”>
<xs:complexType>
<xs:sequence>
<xs:element ref=”ProductTitle”/>
<xs:element ref=”ProductCode”/>
<xs:element ref=”ProductPriceRange” />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>


Advantage of Salami Slice:

[*] Transparent content. The components which make up Product are visible to other schemas, and to other parts of the same schema. The impact of this is that the types and elements within Product are reusable.

[*] Global scope. All components have global scope. The impact of this is that, irrespective of the value of elementFormDefault, the namespace of  ProductTitle and ProductCode will be exposed in instance documents.

[*] Verbose. Everything is laid out and clearly visible.

[*] Coupled. In this example we saw that the Product element depends on the ProductTitle and ProductCode  elements. If those elements were to change it would impact the Product  element. Thus, this design produces a set of interconnected (coupled) components.


[NOTE]

If your document is supposed to be an XML schema, then it must start
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”&gt;
You can use a different namespace prefix if you like (some people prefer “xsd” to “xs”) but the namespace URI must be exactly as written. It’s a URI not a URL – a symbolic constant that identifies the XML vocabulary as being the XML schema vocabulary. If you use a different namespace, then it’s not an XML schema any more.

In my next post I will explain about using  the Russian Doll approach. Wait for that 🙂


Thanks
R Vashi

Advertisements

One thought on “Writing XML Schema using Salami Slice Approach

  1. Kaitlynnk Molinaroo

    Thank you a lot for sharing this with all folks you actually recognise what you’re speaking approximately! Bookmarked. Kindly additionally seek advice from my web site =). We may have a hyperlink change contract between us!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s