This article was started after reading this question on forum.

 

Introduction


Schema is a definition of a document which describes the structure of that particular document. In BizTalk there are two common types of structures which mainly deal with XML based and Flat Files.This article intends to explain bits and bytes of designing BizTalk Schema(XML).

Example used in article 



  <?xml version="1.0" encoding="utf-16" ?>
- <xs:simpleType name="eMailType">
- <xs:restriction base="xs:string">
  <xs:pattern value="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
  </xs:restriction>
  </xs:simpleType>
- <xs:element name="Order">
- <xs:annotation>
- <xs:appinfo>
- <b:properties>
  <b:property distinguished="true" xpath="/*[local-name()='Order' and namespace-uri()='http://TestingSchemas.IncomingOrder']/*[local-name()='Header' and namespace-uri()='']/*[local-name()='OrderId' and namespace-uri()='']" />
  <b:property distinguished="true" xpath="/*[local-name()='Order' and namespace-uri()='http://TestingSchemas.IncomingOrder']/*[local-name()='Header' and namespace-uri()='']/*[local-name()='OrderDate' and namespace-uri()='']" />
  </b:properties>
  </xs:appinfo>
  </xs:annotation>
- <xs:complexType>
- <xs:sequence>
- <xs:element name="Header">
- <xs:complexType>
- <xs:sequence>
  <xs:element name="OrderId" type="xs:string" />
  <xs:element name="OrderDate" type="xs:string" />
  <xs:element name="Currency" type="xs:string" />
- <xs:element minOccurs="0" maxOccurs="1" name="ShipTo">
- <xs:complexType>
- <xs:sequence>
  <xs:element name="ID" type="xs:string" />
  <xs:element name="Name" type="xs:string" />
  <xs:element name="AddressLine1" type="xs:string" />
  <xs:element name="AddressLine2" type="xs:string" />
  <xs:element name="City" type="xs:string" />
  <xs:element name="State" type="xs:string" />
  <xs:element name="PostalCode" type="xs:string" />
  <xs:element name="Country" type="xs:string" />
  <xs:element name="TelephoneNumber" type="xs:string" />
  <xs:element name="EmailAddress" type="eMailType" />
  </xs:sequence>
  </xs:complexType>
  </xs:element>
- <xs:element minOccurs="0" maxOccurs="1" name="BillTo">
- <xs:complexType>
- <xs:sequence>
  <xs:element name="ID" type="xs:string" />
  <xs:element name="Name" type="xs:string" />
  <xs:element name="AddressLine1" type="xs:string" />
  <xs:element name="AddressLine2" type="xs:string" />
  <xs:element name="City" type="xs:string" />
  <xs:element name="State" type="xs:string" />
  <xs:element name="PostalCode" type="xs:string" />
  <xs:element name="Country" type="xs:string" />
  <xs:element name="TelephoneNumber" type="xs:string" />
  <xs:element name="EmailAddress" type="eMailType" />
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  <xs:element name="HeaderComment" type="xs:string" />
  </xs:sequence>
  </xs:complexType>
  </xs:element>
- <xs:element name="Details">
- <xs:complexType>
- <xs:sequence>
- <xs:element minOccurs="1" maxOccurs="unbounded" name="Item">
- <xs:complexType>
- <xs:sequence>
  <xs:element name="ItemId" type="xs:string" />
  <xs:element name="ItemDescription" type="xs:string" />
  <xs:element name="Quantity" type="xs:string" />
  <xs:element name="UnitPrice" type="xs:string" />
  <xs:element name="LineNumber" type="xs:string" />
  <xs:element name="UOM" type="xs:string" />
  <xs:element name="RequestedDeliveryDate" type="xs:string" />
  <xs:element name="LineComment" type="xs:string" />
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:schema>
Code Block 1. Sample schema 

Building blocks of schema

Schema is created with the help of following components:

  1. BizTalk Schema Editor.
  2. Encoding.
  3. Namespace.
  4. Properties.
  5. Root Node and properties associated with it.
  6. Record Node and properties associated with it.
  7. Element and properties associated with it.
  8. Attributes and properties associated with it.
  9. Properties associated with Schema.

BizTalk Schema Editor


The BizTalk Editor shows the schema in two sections, first section on left shows  the tree view and the second section shows the XSD code.
Properties window can be found at right bottom of the screen, which is used to set properties of the nodes. 

Note: XSD code can only be viewed and cannot be edited.

Figure 1. BizTalk Schema Editor.

Encoding

BizTalk always uses UTF-16 encoding for their schemas.

<?xml version="1.0" encoding="utf-16" ?>

Namespace


By default, the BizTalk Editor will set the namespace of a schema to http://ProjectName.SchemaName. 

Note: http://schemas.microsoft.com/BizTalk/2003 and http://www.w3.org/2001/XMLSchema are also added by BizTalk and are implicit. Basically both are references to definitions,annotations defined by BizTalk and W3.org, it is the reason why we are able to build schema.


Common Properties across Root Node,Record Node,Element Field,Attribute Field

Properties

Description

Available For

Base Data Type

Determines the name of the type definition that the current node type is based upon.

Root Node, Record Node, Element Field,Attribute Field

Block

The Block property is used to prevent specific types of derivation to be used in place of this Node. Default value is ’None’.

Root Node, Record Node

Content Type

Content model of the complex type (either of ComplexContent, SimpleContent,None).Default is ‘None’.

Root Node, Record Node

Data Structure Type

Indicates the structure type of the record. Usually is a global complex type or named reference to a global element.

Root Node, Record Node

Group Max Occurs

Maximum Occurrences of the underlying group content of this Node. Its value should always be greater than or equal to Group Min Occurs. Default value is ‘1’.

Root Node, Record Node

Group Min Occurs

Minimum Occurrences of the underlying group content of this Node. Its value should always be less than or equal to Group Max Occurs. Default value is ‘1’.

Root Node, Record Node

Group Order Type

Determines the type of group ordering for children nodes under the current context. Available options are Sequence, Choice, All.

Root Node, Record Node

Mixed

Determines whether the sub elements in the current context can be intermingled with text content. Default is ‘False’.

Root Node, Record Node

Nillable

Determines whether this node can be null in the instance document. Default is ‘False’.

Root Node, Record Node, Element Field

Node Name

Name of the Node.

Root Node, Record Node, Element Field, Attribute Field

Notes

This property is used to access a dialog for entry of what are effectively business level comments about the node with focus.

Root Node, Record Node, Element Field, Attribute Field

Max Occurs

Maximum Occurrences of this node.Its value should always be greater than or equal to minOccurs of this node. Use ‘unbounded’ or ‘*’ to indicate unlimited occurrences. Default value is ‘1’.

Record Node, Element Field

Min Occurs

Minimum occurrences of this node. Its value should always be less than or equal to MaxOccurs for this node. Default value is ‘1’.

Record Node, Element Field

Data Type

Data Type of the Node

Element Field, Attribute Field

Default Value

Default value of this node

Element Field, Attribute Field

Derived By

Indicates how the underlying Simple Type of the Field is derived from its base data type. Options available are Restriction, List and Union.

Element Field, Attribute Field

Fixed

The fixed attribute is used to ensure that the field is set to particular fixed value.

Element Field, Attribute Field

Form

During instance validation, determine whether the items in the current context must be qualified with a namespace. Options are Qualified and Unqualified.

Element Field, Attribute Field

Table 1. Listing of common properties,description and available for.

Root Node and properties associated with it

Root node is a special type of Record Node which has at least one child and no parent. Whenever you create a schema in BizTalk schema editor a Root node will be added automatically with name as "Root".It can be renamed, and its best practice to name it after the purpose , say "Order" if it is for order.




Figure 2.Properties available for Root Node.

Record Node and properties associated with it



Figure 3.Properties available for Record Node.

Element and properties associated with it


Figure 4.Properties available for Element Field.

Attributes and properties associated with it


Figure 5.Properties available for Attributes.

Properties associated with Schema

 
Figure 6.Properties available for Schema.

[More Content will be added soon]



Author

Maheshkumar S. Tiwari
iVision Software Pvt Ltd|User Page
http://tech-findings.blogspot.com/


See Also


Another important place to find a huge amount of BizTalk related articles is the TechNet Wiki itself. The best entry point is BizTalk Server Resources on the TechNet Wiki.

Another important place to find a huge amount of TechNet Wiki related articles is Wiki: List of Articles for TechNet Wiki

This article participates in the TechNet Guru for September competition