1. Problem
As part of your business
process or messaging solution, you need to create an XML schema from
scratch. You can't generate a schema based off of an existing XML
document, as this schema represents data that has not been modeled
before.
2. Solution
The following steps outline
how to create a simple schema and add it to your BizTalk project.
Open
an existing project or create a new project in Visual Studio.
As shown in Figure 1, right-click the project name in the
Solution Explorer and select Add => Add New Item.
The Add New Item dialog box will
appear, as shown in Figure 2. Select Schema as the type of item, type in a name
for the item, and click OK.
To change the name of the root
node, right-click the node, and select Rename.
To
add nodes, right-click a node, and select Insert Schema Nodes. Then
select from the following options, as shown in Figure 3:
Child Record, to add a new
record indented one level from the selected node
Child Field Attribute, to add a new
attribute node indented one level from the selected node
Child Field Element, to add a new
element node indented one level from the selected node
Sibling Record, to add a new
record node at the same level of the selected node
Sibling Field Attribute, to add a
new attribute node at the same level of the selected node
Sibling Field Element, to add a
new element node at the same level of the selected node
Select a node to view and
modify its properties.
3. How It Works
XML schemas are the
foundation of all scenarios and document exchanges with BizTalk Server.
Once you have created your schema, you can create your scenario. Whether
it is a pure messaging solution or involves business process automation
scenarios implemented as orchestrations, the schema is available to all
other projects and solutions simply by referencing it. Additionally,
once you have created your schema, you can generate instances of the
document that will adhere to the schema definition. This feature makes
it very easy to create test data.
To generate a test
instance, follow these steps:
Open the schema
Properties, shown in Figure 4, by right-clicking the schema in the Solution
Explorer and selecting Properties.
Type a path and file name next to
Output Instance Filename, or select the ellipsis to use the common file
dialog box to browse to a file location and name the file. Then click
OK.
Right-click the schema, and select Generate Instance. A
test instance of the document will be created and named based on the
Output Instance Filename property specified.
Similarly, BizTalk Server
provides the ability to validate that an instance of a document adheres
to a schema definition. To validate an instance, follow these steps:
Open
the schema Properties by right-clicking the schema name in the Solution
Explorer and selecting Properties.
Type
a path and file name next to Input Instance Filename, or select the
ellipsis to use the common file dialog box to browse to a file location
and select a file. Then click OK.
Right-click
the schema, and select Validate Instance. The document specified in the
Input Instance Filename property will be validated against the schema.