Module 2: Creating Schemas Time estimated: 90 minutes Module objective: In this module, you will learn how to: Create and test XML and flat file schemas. Introduction Microsoft® BizTalk® Server 2010 can receive messages formatted as XML, flat files, or as Electronic Document Interchange (EDI). Regardless of the format of the incoming message, the BizTalk orchestration and messaging engine always processes messages in XML format. This requires that a schema be defined in order to convert the message to XML format that can be processed by BizTalk. In the case of flat file or EDI messages, XSD (XML Schema Definition) annotations are used within the schemas to provide the additional information required by the relevant parsers. This module provides the knowledge and skills necessary for developers to create XML and flat file schemas. Lesson 1: Introduction to BizTalk Schemas Lesson objective: Describe how BizTalk uses XML and identify the types of XML message types supported by BizTalk. Introduction Creating schema definitions for the messages to be processed by BizTalk is usually the first step in developing an integration solution. This lesson provides a review of XML terminology that you may already be familiar with and identifies how BizTalk implements XML standards. In this lesson, you will learn how BizTalk uses namespaces as well as the various schema types that can be created for use by BizTalk. Reviewing XML Terminology Describe XML terminology as it pertains to BizTalk. Overview BizTalk Server was one of the first applications specifically designed to work with data in XML format. All documents (messages) that will be internally processed by BizTalk must first be converted to XML. All XML artifacts that are created by BizTalk are fully World Wide Web Consortium (W3C) compliant. This means that schemas created using other tools can generally be used by BizTalk and vice versa. XML Terminology The following are some of the terms and XML features supported by BizTalk Server 2010: Namespace. An XML namespace is a W3C standard for providing uniquely named elements and attributes in an XML instance. An XML instance may contain element or attribute names from more than one XML vocabulary. If each vocabulary is given a namespace, the ambiguity between identically named elements or attributes can be resolved. Element. An XML element is a construct used to organize information in a hierarchical manner. XML elements can either be simple data types (such as strings, decimals, and unsigned bytes) as defined in W3C standards, or they may be a complex type containing other elements and/or attributes. Elements and attributes are case sensitive; that is, Customer is not the same element name as customer or CUSTOMER. Attribute. An XML attribute is a construct used to associate additional information contained with an XML element. Unlike elements, attributes cannot be nested. Attributes can be associated with any of the simple data types, but because they cannot be nested, they cannot be a complex type. In the following example, Customer is an element with a value of Contoso. ID is an attribute of the Customer element and has a value of 12345. <Customer ID=”12345”>Contoso</Customer> XML Schema Definition Language (XSDL). The XML schema definition language is used to create schemas that represent the message formats that BizTalk will process. Schemas define nodes such as required and optional fields, recurring fields, and order. An instance message can be validated against an XSD to verify that the format is valid. XML Path Language (XPath). A language used for navigating through the hierarchy of an XML document. For example, XPath can be used to select data in an XML document that matches a certain criterion or to perform comparisons on retrieved data. Extensible Style Sheet Language Transformation (XSLT). A language definition for XML data presentation and data transformations. Data presentation refers to how data is formatted for display purposes in a specific format or style. Data transformation refers to how data is transformed and exchanged. For example, a purchase order could be converted from the format submitted by a trading partner to the format required for your internal processes. Document Object Model (DOM). The DOM provides a mechanism for navigating through a message. When working with XML documents, the DOM is often used to manipulate and query XML data. In BizTalk, when references are made to the XML DOM, it is usually presumed that the message is being loaded into memory, which results in slower processing than would be experienced if the data were simply being streamed. Web Services Description Language (WSDL). An XML format that describes the capabilities and characteristics of a Web service. BizTalk can both publish and consume Web services. That will be discussed in module 12. Simple Object Access Protocol (SimpleSOAP). Defines a simple way of sending XML messages across the Internet. SOAP is used in BizTalk Server in conjunction with Web services. What Are XML Namespaces? Explain what an XML namespace is. Overview An XML namespace is a W3C standard for providing uniquely named elements and attributes in XML instances. XML namespaces help the BizTalk parser recognize the proper schema or schemas as well as the tags that describe the structure of the data inside the schema. XML Namespaces XML messages (instances) may contain elements or attributes from more than one XML vocabulary. If each vocabulary is given a namespace, the ambiguity between identically named elements or attributes can be resolved. Element names within a namespace must be unique. A simple example of ambiguous elements would be to consider an XML instance that contains references to a customer and an ordered product. Both the customer and product elements could have a child element ID_number. References to the element ID_number would therefore be ambiguous. By providing namespace references, the two identically named but semantically different elements can be differentiated. A namespace is declared by using the reserved XML attribute xmlns, the value of which must be a Uniform Resource Identifier (URI). The declaration generally also includes a short prefix with which elements and attributes can be identified, such as xmlns:prod="http://adventure- works.com/customerOrderl". A maximum of one namespace per schema (the default namespace) has no prefix. Any elements that are not associated with a prefix will be presumed to belong to this namespace. In the following example, the default namespace is http://adventure-works.com/salesReport, whereas the products namespace (http://adventure-works.com/products) has a prefix of prod. Without the namespace reference, the id element as used in the customer and for the product would be ambiguous. <salesReport xmlns="http://adventure-works.com/salesReport" xmlns:prod="http://adventure-works.com/products"> <customer> <id>Fabrikam</id> <sales> <prod:id>widget1004</prod:id> <prod:unitsSold>100</prod:unitsSold> <prod:price>35</prod:price> </sales> </customer> </salesReport> How Does BizTalk Use XML Namespaces? Explain how BizTalk uses XML namespaces. Overview As previously stated, BizTalk Server relies on the use of structured documents for all internal messaging and orchestration operations. BizTalk uses W3C standard format XSD but extends these by referencing additional namespaces. This results in schemas that can still be used by other systems that understand XML and contain the additional parameters required by BizTalk. It should be noted that BizTalk can process strictly binary data—for example, .bmp files and .pdf files through its routing functionality—from one location to another, and, in this case, an XML schema is not required. This special handling requires the use of a pass-through pipeline, which will be addressed in Module 5. BizTalk Namespaces BizTalk adds the following namespaces to schemas as necessary to facilitate custom functionality: Target Namespace. When creating new schemas by using the BizTalk Editor, a target namespace is added by default. This namespace is used in conjunction with the root node name to uniquely identify the schema that relates to an inbound message. Other operations within BizTalk also rely upon the target namespace. Schema Extensions Namespace. When working with flat file and EDI schemas, BizTalk will add a reference to the namespace shown below. This reference provides the extensions necessary to define delimiters and positional settings while still allowing the creation of XSD-compliant schemas that can be used by applications other than BizTalk. xmlns:b="http://schemas.microsoft.com/BizTalk/2003 How Does BizTalk Server Determine Which Schema Relates to an Incoming Message? When an XML message is received by BizTalk, the default namespace and root node name are extracted from the message. These values are concatenated (targetNamespace#rootNodeName) and are referred to as the Message Type. It is important that the Message Type be unique so that BizTalk can non-ambiguously determine the correct schema to be applied to the instance. For non-XML message instances, a property defined in the pipeline will specify the schema to be applied. Schemas used for flat file processing will have a root node name and a target namespace and will therefore have a message type. These values should provide for uniqueness but are not as critical. More information about these properties will be provided later in this module. What Is a BizTalk XML Schema? Describe how BizTalk uses XML and what is defined in BizTalk XML schema. Overview XML schemas define the data structure for all XML business documents that you exchange within and across organizations by using BizTalk. BizTalk also requires schemas in order to have an XML representation of the flat file messages that it will be processing. BizTalk Schemas BizTalk can use schemas provided by trading partners or created by using other third-party schema creation tools and applications. BizTalk includes tools for creating (or modifying) schemas, including schemas to be used for flat file processing. Generally speaking, it is a good idea to get in the habit of creating your schemas by using the BizTalk Editor, which will be discussed in the next lesson. A typical XML or flat file document might be a purchase order, an invoice, or any other type of document representing a business transaction. Each unique document type requires a separate schema that defines the records and fields contained in that document. The XML schema defines: Elements and attributes, which are the building blocks of a schema. Data types that appear in document instances, including simple and complex data types. Simple data types, which are data types that contain data and cannot be nested. Examples of simple data types include xs:string, xs:int, and xs:long. Elements or attributes can be simple data types. Complex data types. Complex data types can contain both data and nested data. For example, in the slide for this section, the Item element is a complex type because it contains other elements. Only elements can be complex data types; an attribute must be associated with one, and only one, element. Namespace declarations and version information. The ordering of tags in the document. Fields that are mandatory or that may occur multiple times in a single document. XSD Resources on the Web For more detailed information, go directly to the XSD specifications and primer maintained on the W3C Web site. Supported BizTalk Schema Types Identify the types of schemas that BizTalk supports. Schema Types BizTalk Server 2010 can natively process messages in XML flat file and EDI message formats. BizTalk is extensible, and custom message types can be created in addition to those supported out of the box. XML Schema An XML schema defines the structure of XML messages. XML messages are arranged in a hierarchical format that is defined by the schema. Messages are identified and validated against their associated schema. Flat File Schema A flat file schema defines the structure of messages that use a flat file format. Flat files can be either delimited or positional. Because XSD does not natively support the flat file structure, BizTalk uses the annotation capabilities of XSD to store this extra information within the XSD schema. BizTalk defines a rich set of specific annotation tags that can be used to store all of the required additional information. EDI Schema BizTalk supports the creation and use of schemas that represent various EDI document formats such as EDIFACT and X12. An EDI message is a variation of a text message and does not use typical delimiters such as carriage returns and linefeeds. As with flat file schemas, BizTalk uses the annotation capabilities of XSD to store the extra information related to the format of the EDI messages. EDI messages are beyond the scope of this course. Refer to the BizTalk help files for additional information on EDI schemas and their uses. Flat File Structures Identify the types and characteristics of flat file messages that can be processed by BizTalk. Flat Files BizTalk Server is designed to make it easy to create schemas for positional flat files, delimited flat files, and files that combine positional and delimited records. At the root level, most flat files are delimited with a carriage return (for example UNIX files), a linefeed, or, more frequently, both. For this reason, even files that contain mostly positional data will be defined as delimited at the root. Delimited Files A delimited file contains one or more fields separated by a delimiter character. This character is frequently a comma (,) or pipe symbol (|) but could be any character. BizTalk Editor does not read delimiters as part of the data. However, if the delimiter character might appear within the instance as valid data, the data can be formatted so that what would otherwise be a delimiter character is treated as valid data. In the following example, the record contains four fields that are delimited with commas. The fields are first name, last name, address, and a comment. The comment contains a comma that would normally be interpreted as a delimiter. With the comment enclosed in quotes (“”) the embedded comma is treated as part of the data. John, Smith, 123 Main St, “BizTalk, Learning BizTalk Server 2010” ¶« Positional Flat Files A positional flat file is made up of records that have a common end-of-record terminator (delimiter), for example, a carriage return, and fields that have a fixed length. The structure of an incoming file must be represented in the records and fields of the schema so that the positional nature of the incoming file is preserved. Therefore, before defining the structure of a flat file message, you must obtain a layout of the necessary records and fields, and you must obtain a sample message for testing purposes. In the following example, the record contains four fields that are positional delimited. The first name is contained within the first 10 characters, the last name is the next 10 characters, the address is the following 20 characters, and 35 characters are left for the comment. There is no need to enclose the comment in quotes because the position within the instance is used to identify the separation between the fields. The record is terminated with a combination of a carriage return and linefeed. Spaces in the example were replaced by dots to make them more distinguishable. John……Smith…..123.Main.St………Learning BizTalk Server 2010…….¶« Lesson 2: Creating XML and Flat File Schemas Lesson objective: Create an XML schema by using the BizTalk Editor and create a flat file schema by using the Flat File Schema Wizard. Overview In this lesson, students will learn how to use the BizTalk Editor and the Flat File Schema Wizard to create BizTalk schemas. Students will also learn how to import existing schemas and how to validate a schema and generate a schema instance. Methods for Creating BizTalk XML Schemas Identify the methods and tools available for creating XML and flat file schemas. Schema Creation Methods There are several ways in which you can create XML schemas in BizTalk Server 2010, and all will produce valid XSD schemas. Generating a schema from an instance message. You can generate an XML schema that corresponds to a particular instance message as long as that instance message consists of well-formed XML. Migrating an older XML-Data Reduced (XDR) schema to an XSD schema. You can generate an XML schema for BizTalk Server 2010 from a schema that was developed by using a previous version of BizTalk Server, which stored schemas in XDR format. There is also an option to import from Document Type Definitions (DTDs). Creating a schema from scratch. You may use this method to create schemas for messages for which no instances exist (possibly for internal use), or when the other tools do not provide the necessary functionality. This would be a way of creating schemas for XML, flat file, or EDI message types. Creating a schema from scratch in conjunction with other schemas. When creating complex schemas in the real world, you are more likely to build them by modifying existing schemas by using the XSD language processes of importing, including, and redefining schemas created previously. Modify existing schemas. Regardless of the original source of any schema, the BizTalk Schema Editor can be used to modify any valid XSD schemas. Flat File Schema Wizard. The Flat File Schema Wizard is new to BizTalk Server 2010 and makes the creation of flat file schemas easier than ever before. Generating Schemas Generate a schema from an instance, an XDR schema, and a DTD file. Overview You can use the Generate Schemas dialog box to generate an XSD schema from one of the following sources: A well-formed XML instance message A valid XDR schema A valid DTD In each of these cases, you would begin by adding a new generated item to the project (right click the project, click Add, and then click New Generated Item) and then browsing to locate the appropriate source file. A new schema with the same name as the source file is created in the current solution. This schema can be renamed and, if necessary, edited using the BizTalk Editor. Generate a Schema from an XML Instance You may frequently be provided with an instance of an XML message for which no schema is available. Because BizTalk always requires a schema for messages to be processed, it will be necessary to generate a schema. Generate Schemas from XDR Schemas and DTD Files XDR was an early Microsoft standard for creating schemas. BizTalk Server 2000 and BizTalk Server 2002 used XDR to create schemas. XSD replaced XDR as the BizTalk schema type starting with BizTalk Server 2004. DTD was the first method used for validating documents, but it was not XML based and has since been replaced by XSD. Although DTD was never a standard supported by BizTalk, you may need to generate schemas that can validate messages generated using DTD. This will produce a valid XSD to be used to validate instances that were created based on a DTD. Installing the Schema Generators for XML and DTD In the case of generating a schema from an XML instance or from a DTD file, it is necessary to install the schema generator before the first use. This is done by executing the appropriate script located at C:\Program Files (x86)\Microsoft BizTalk Server 2010\SDK\Utilities\Schema Generator. The script to install the schema generator for well-formed XML messages is named InstallWFX.vbs. The script for generating a schema from a DTD is named InstallDTD.vbs. After one of these scripts has been executed, the appropriate generator is added in Microsoft Visual Studio 2010. Creating a Schema by Using the BizTalk Editor Create a schema by using the BizTalk Editor. BizTalk Editor The BizTalk Editor automatically starts when you add a new schema to a BizTalk project or open an existing schema in the project. You can use the BizTalk Editor to construct and modify schemas without the need to learn all of the intricacies of XSD syntax. The schema tree view is where you actively construct your schema. The XSD view is a read-only view that represents the XSD syntax for the schema you are creating. When creating or viewing flat file schemas, this view has an additional page named Flat File that shows the delimiters and positional spacing in use. BizTalk creates (and uses) fully W3C-compliant schemas. More information about elements, attributes, data types, and schema design is available through many online resources, including MSDN®. Node Types The following menu choices are available when inserting nodes into a schema tree: Field Element. Represents items of information that are simple in nature, such as strings and numbers. You must use a record if the field has children or is repeated. Field Attribute. Represents items of information that are simple in nature, such as strings and numbers. Child Record. A record is a container object (it cannot directly contain data) that represents a collection of information. Records have the record icon associated with them but are implemented as complex data type elements in the schema. A record node can include element or attribute nodes based on simple data types such as strings and numbers or can provide nesting of other complex data types (sequence group or choice group). Sequence Group. Contains other nodes that must appear in an instance message in the same order in which they appear within the Sequence Group node. Auto-Refresh When working with large schemas, auto-refresh might cause undesirable delays. In such cases, you can disable automatic (continuous) refresh by clicking the link at the bottom of the window. You can then click the refresh link as needed to refresh the XSD view. Using Multiple Schemas Create and combine schemas by using an existing schema structure. Overview When your schemas become large and complex, or when schemas that represent different types of instance messages have some sections in common, it can be useful to include smaller schemas as building blocks in the larger ones. For example, you might have several message types, each of which must contain a shipping address. You can define the structure of a shipping address in a single smaller schema and then include that schema within the other, larger schemas that define Order, Invoice, and Shipping Notice messages. If this format changes, there is a single place to update rather than having to update it at each occurrence. Methods for Combining XSD provides the import, include, and redefine mechanisms for using multiple schemas together. To be able to use schemas in this way, a target namespace must be specified for the schema that will be imported. All three of these mechanisms are supported by BizTalk Editor and are described here: Import. Importing a schema provides a mechanism for using types defined in other namespaces. An imported schema must have a Target Namespace that is different from the importing schema, and no type modification is allowed to the imported schema. This means that the imported schema cannot be modified in any way once it has been imported. Use the import option to import a schema. Include. Including a schema provides a mechanism for using types defined in the same namespace as the including schema. The namespace of the included schema can be empty, and, as in importing a schema, no type modification is allowed. Use the include option to include a schema. Redefine. Redefining a schema is similar to including a schema in that it provides a mechanism for using types defined in the same namespace as the including schema or for a namespace that is empty. However, you can use types defined in the redefined schema as is, derive new types from them, or specify modifications to them. Use the redefine option to redefine a schema. Testing a Schema Test and validate a schema and generate a sample instance message. Overview After you have constructed or added a schema into your BizTalk project, you can perform several operations to make sure the newly created schema can correctly validate data. Regardless of the format of the messages they represent, all schemas can be tested using these methods. You can also generate sample instance documents, which are helpful for comparing against provided instances. Testing a Schema There are three tests that can be performed on any schema to validate that it is a well-formed XSD and that it can be used to validate message instances. All of these tests can be configured in the Microsoft .NET properties of the schema (accessed by right-clicking the schema in Solution Explorer and then clicking Properties). To perform any of these tests, right-click the schema in Solution Explorer, and then click the appropriate menu command. The tests are as follows: Validate Instance. This test is extremely useful when you have an XML or flat file document with data that you would like to make sure is valid against a schema. In many cases, you may find that one instance may validate while another will not, for example, if the schema was generated with a message that had a single product instance but you need to validate messages that also have multiple products. Validate Schema. Schemas generated within BizTalk will always be valid XSD because BizTalk enforces such rules as the schema is created; however, schemas provided by others may not adhere to W3C standards as strictly. This step ensures that the XSD has valid syntax. This step is most often necessary when adding an existing schema into a project that was not built by the BizTalk Schema Editor. Generate Instance. You can use this option to generate a sample instance message. The sample instance message that is generated contains the element and attribute structure specified by the schema and generates data type–specific sample data. You can populate this generated instance with realistic data to use in the validate instance process specified earlier or provide it to partners as a sample of the messages your processes may output. You might find it useful to add a folder named Messages inside the BizTalk project into which the generated instances and test messages can be saved. In this way, the test messages are always accessible for future testing and schema modification. Demonstration: Creating and Testing a Schema In this demonstration, you will see how to create a new BizTalk schema by using BizTalk Editor. You will then see how to generate an instance of the schema and test the schema against a sample message. Create a Schema 1. If it is not already started, start the bt10d-demos virtual machine. 2. In Microsoft Windows Explorer, navigate to C:\AllFiles\Democode\Module2\Demo, and then double-click Demo.sln. 3. In Solution Explorer, right-click the Messaging project, point to Add, and then click New Item. 4. In the Add New Item dialog box, in the center pane, click Schema. 5. Change the Name to PurchaseOrder.xsd, and then click Add. 6. In the left pane of BizTalk Editor, right-click the Root node, and then click Rename. 7. Rename the node to PO. The Root node should always be renamed. 8. Right-click PO, point to Insert Schema Node, and then click Child Record. 9. Name the record Customer. 10. Right-click PO, point to Insert Schema Node, and then click Child Record. 11. Name the record Address. 12. Right-click PO, point to Insert Schema Node, and then click Child Record. 13. Name the record Items. 14. Right-click Customer, point to Insert Schema Node, and then click Child Field Attribute. 15. Name the attribute FirstName. 16. Right-click Customer, point to Insert Schema Node, and then click Child Field Attribute. 17. Name the attribute LastName. 18. Right-click Customer, point to Insert Schema Node, and then click Child Field Attribute. 19. Name the attribute EmailAddress. 20. Right-click Customer, point to Insert Schema Node, and then click Child Field Attribute. 21. Name the attribute PhoneNumber. 22. Right-click Address, point to Insert Schema Node, and then click Child Field Element. 23. Name the element Street. 24. Right-click Address, point to Insert Schema Node, and then click Child Field Element. 25. Name the element City. 26. Right-click Address, point to Insert Schema Node, and then click Child Field Element. 27. Name the element State. 28. Right-click Address, point to Insert Schema Node, and then click Child Field Element. 29. Name the element Zip. 30. Right-click Items, point to Insert Schema Node, and then click Child Record. 31. Name the record Item. 32. Right-click Item, point to Insert Schema Node, and then click Child Field Attribute. 33. Name the attribute SKU. 34. Right-click Item, point to Insert Schema Node, and then click Child Field Attribute. 35. Name the attribute Description. 36. Click the Item record. 37. In the Properties window, scroll to the bottom of the list, set the Max Occurs property to *, and then set the Min Occurs property to 1. Setting the Min Occurs and Max Occurs properties as shown will make this a required node within the message (it must occur at least once but can repeat infinitely). Generate an Instance 1. In Solution Explorer, right-click PurchaseOrder.xsd, and then click Properties. 2. In the Properties window, click Output Instance Filename, and then click the ellipsis button (…). 3. In the Select Output File dialog box, navigate to C:\AllFiles\DemoCode\Module2, in the File name box, type PurchaseOrder-Gen, and then click Save. 4. In Solution Explorer, right-click PurchaseOrder.xsd, and then click Generate Instance. 5. In Windows Explorer, navigate to C:\AllFiles\DemoCode\Module2, and then open PurchaseOrder-Gen.xml. Notice that each node has been populated with sample data. 6. Close Microsoft Internet Explorer. Test the Schema 1. In Solution Explorer, right-click PurchaseOrder.xsd, and then click Properties. 2. In the Properties window, click Input Instance Filename, and then click the ellipsis button (…). 3. In the Select Input File dialog box, navigate to C:\AllFiles\Democode\Module2, click Message1.xml, and then click Open. This message represents a sample message from another system. 4. In Solution Explorer, right-click PurchaseOrder.xsd, and then click Validate Instance. 5. In the Output window, notice the message that reads Component invocation succeeded, and then click the file:///C:\AllFiles\DemoCode\Module2\Message1.xml link while holding CTRL. The message is displayed. 6. Pause the bt10d-demos virtual machine. Using the Flat File Schema Wizard Create a schema by using the Flat File Schema Wizard. Overview The BizTalk Server toolset includes parsers and serializers for transforming data between EDI or flat file formats and XML format. BizTalk Server 2010 solves the problem of creating schemas for flat files by introducing a new tool called the Flat File Schema Wizard. Using the Flat File Schema Wizard The Flat File Schema Wizard provides a series of steps that allow you to quickly generate an XSD for even quite complex flat file messages. Once this base XSD has been created, it can then be opened by using either the BizTalk Schema Editor or another schema design tool and edited further if necessary. To launch the Flat File Schema Wizard, add a new item to an existing BizTalk project, and choose the Flat File Schema Wizard option. In the BizTalk Flat File Schema Wizard dialog box, browse to the flat file that you want to use as a source. As you progress through the wizard, each record is identified, and then within these records, each element or attribute is identified by name and data type. Each item that is identified as a record or repeating record will cause the wizard to loop back through the process until all nodes are identified. Demonstration: Creating and Testing a Flat File Schema In this demonstration, you will see how to create a flat file schema from a sample message by using the Flat File Schema Wizard. You will then see how to test a flat file schema. Create a Flat File Schema 1. Resume the bt10d-demos virtual machine. 2. If the Visual Studio solution is not already open, in Windows Explorer, navigate to C:\AllFiles\Democode\Module2\Demo, and then double-click Demo.sln. 3. In the center pane, click Flat File Schema Wizard, in the Name box, replace the existing text with PurchaseOrderFF.xsd, and then click Add. 4. On the Welcome page of the Flat File Schema Wizard, click Next. 5. On the Flat File Schema Information page, click Browse. 6. In the Select a Flat File Document dialog box, browse to and click C:\AllFiles\Democode\Module2\PurchaseOrderFF.txt, and then click Open. 7. On the Flat File Schema Information page, in the Record name box, replace the existing text with Order, and then click Next. 8. On the Select Document Data page, ensure that the entire message is selected, and then click Next. 9. On the Select Record Format page, ensure that By delimiter symbol is selected, and then click Next. 10. On the Delimited Record page, ensure that the Child delimiter is set to {CR}{LF}, select the Record has a tag identifier check box, in the Tag box, type PO, and then click Next. 11. On the Child Elements page, set the Element Name and Element Type for each of the elements in the following table, and then click Next. Element Name Element Type PODetail Record Address Record Items Record 12. On the Schema View page, ensure that PODetail is selected, and then click Next. 13. On the Select Document Data page, click Next. 14. On the Select Record Format page, ensure that By delimiter symbol is selected, and then click Next. 15. On the Delimited Record page, in the Child delimiter list, click the comma (,) symbol, and then click Next. 16. On the Child Elements page, set the Element Name, Element Type and Data Type for each of the elements in the following table, and then click Next. Element Name Element Type Data Type OrderNumber Field attribute string CustomerName Field attribute string OrderDate Field attribute date 17. On the Schema View page, ensure that Address is selected, and then click Next. 18. On the Select Document Data page, click Next. 19. On the Select Record Format page, click By relative positions, and then click Next. 20. On the Positional Record page, click the position to the left of each of the elements. You should have an arrow in each of the following positions: 0 (default), 24, 39, 41. 21. Click Next. 22. On the Child Elements page, set the Element Name and Element Type for each of the elements in the following table, and then click Next. Element Name Element Type Street Field element City Field element State Field element Postal Field element 23. On the Schema View page, ensure that Items is selected, and then click Next. 24. On the Select Document Data page, click Next. 25. On the Select Record Format page, ensure that By delimiter symbol is selected, and then click Next. 26. On the Delimited Record page, using the drop-down list, change the Child Delimiter to the comma (,) symbol, and then click the Record has a tag identifier check box. 27. In the Tag box, type Items, and then click Next. 28. In the error dialog box, click OK. The Flat File Schema Wizard parses the message to verify that the tag identifier is valid and case-sensitive. Because “Items” is not found within the record, an error is displayed. 29. In the Tag box, type ITEMS, and then click Next. 30. On the Child Elements page, set the Element Name and Element Type for each of the elements in the following table, and then click Next. Element Name Element Type Item Repeating Record Items_Child2 Ignore 31. On the Schema View page, ensure that Item is selected, and then click Next. 32. On the Select Document Data page, click Next. 33. On the Select Record Format page, ensure that By delimiter symbol is selected, and then click Next. 34. On the Delimited Record page, using the drop-down list, change the Child Delimiter to the pipe (|) symbol, and then click the Record has a tag identifier check box. 35. In the Tag box, type ITEM, and then click Next. 36. On the Child Elements page, set the Element Types for each of the Elements in the following table, and then click Next. Element Name Element Type ISBN Field element Description Field element Qty Field element Price Field element 37. Click Finish. Test the Flat File Schema 1. In Solution Explorer, right-click PurchaseOrderFF.xsd, and then click Properties. In the PurchaseOrderFF.xsd properties window, notice that the Input Instance Filename property is the same file that was used to create the schema by using the Flat File Schema Wizard. 2. In Solution Explorer, right-click PurchaseOrderFF.xsd, and then click Validate Instance. 3. In the Output window, hold the CTRL key, and then click the Validate Instance succeeded for schema PurchaseOrderFF.xsd, file: link. The sample message appears in the center pane. 4. In the Output window, hold the CTRL key, and then click the Validation generated XML output link. The flat file message is displayed in an XML format. Notice the repeating Item nodes. 5. On the File menu, click Save All. 6. Close the Visual Studio solution and all other open windows. 7. Shut down the bt10d-demos virtual machine. Building a BizTalk Project Build a schema project into an assembly. Overview A BizTalk project can contain artifacts of many different kinds including schemas, maps, orchestrations, and pipelines. Before using these artifacts in the messaging and orchestration engines, the project needs to be built into an assembly. Building a BizTalk Project Building the project creates a dynamic-link library (DLL) with the same name as the project. The DLL is created in the projectName\bin\Deployment folder. For example, if the EAICBR solution contains a project named EAISchemas, the resulting assembly would be named \EAISchemas\bin\Deployment\EAISchemas.dll. If there are any build errors or warning messages, the Task List window will list these errors and warnings, and double-clicking a task will show you the location of the error or warning. Make sure that you test all schemas in the project with known document instance(s) before compiling and deploying the project. Lab: Creating and Configuring BizTalk Schemas Time estimated: 30 Minutes Scenario Each type of message processed by a BizTalk server application requires an XML schema that defines the structure of the message. In this lab, you will create a BizTalk Server project that will contain your schemas. Adventure Works has defined an internal sales order message format for which you will create a schema. Next you will use the Flat File Schema Wizard to create a schema that represents the format of the sales orders submitted by the Adventure Works stores. Finally, you will generate a schema from a sample loan application message. Start the Virtual Machine Procedure List 1. If the Server Manager window is not already open, click on the Server Manager icon located in the task bar next to the Start button. 2. Expand Roles, Hyper-V, Hyper-V Manager. The last node to appear displays the machine name. Click on it to see the list of virtual machines available. 3. Double-click the virtual machine bt10d-01 to open a Virtual Machine Connection window. 4. Click on the Action menu in the Virtual Machine Connection window and choose Start. 5. Once the virtual machine starts, press CTRL+ALT+END. 6. Log on using the user name Administrator and the password pass@word1. 7. At the Windows Activation prompt, click Ask Me Later, and then click OK. Exercise 1: Creating a New BizTalk Project Overview A BizTalk Server project contains BizTalk Server artifacts. In this exercise, you will create a new Microsoft Visual Studio® 2010 solution and a new project that uses the BizTalk Server Project template. This project will contain the schemas that you will create in the following exercises. Create a Blank Solution Procedure List 1. On the Start menu, click All Programs, click Microsoft Visual Studio 2010, and then click Microsoft Visual Studio 2010. 2. On the File menu, point to New, and then click Project. 3. In the New Project dialog box, in the Installed Templates pane, click BizTalk Projects, click the Empty BizTalk Server Project icon, and then create a new project using the information in the following table. Property Value Name Messaging Location C:\AllFiles\LabFiles\Lab2 Create directory for solution <checked> Solution Name AdvWorks 4. Click OK to create and open the new project. Exercise 2: Creating an XML Schema Overview You can define an XML schema by manually defining each node, or by importing or including other schemas. In this exercise, you will define schema nodes for the Adventure Works sales order message and import nodes from an existing schema that contains customer information. Create the SalesOrder Schema Procedure List 1. In Solution Explorer, right-click the Messaging project, point to Add, and then click New Folder. 2. Rename the folder Messages. 3. In Solution Explorer, right-click the Messages folder, point to Add, and then click Existing Item. 4. In the Add Existing Item dialog box, navigate to C:\AllFiles\LabFiles\Lab2, and then double-click SalesOrder1.xml. This is a sample message of the schema that you will build in this exercise. 5. In Solution Explorer, double-click SalesOrder1.xml to open the message. Examine the structure of the message. 6. In Solution Explorer, right-click the Messaging project, point to Add, and then click New Item. 7. In the Add New Item dialog box, in the Categories pane, then click the Schema icon. 8. In the Name box, type SalesOrder.xsd to name the schema. 9. Click Add to open the blank schema in BizTalk Editor. The schema tree (left pane) and XSD view (right pane) appear in BizTalk Editor. Also, the new schema (SalesOrder.xsd) is added to Solution Explorer. Define the SalesOrder Schema Structure Procedure List 1. In the Schema tree (left pane), right-click the Root node, click Rename, and then rename the node to SalesOrder. The Root node should always be renamed with a meaningful name that represents the type of document described by the schema. When possible, use a root node name that is unique throughout the enterprise. 2. Right-click the SalesOrder (root) node, point to Insert Schema Node, and then click Child Record. 3. Rename the record to Detail. 4. Repeat steps 2 and 3 to create two more records and name them Record and Items. 5. Right-click the Detail node, point to Insert Schema Node, and then click Child Field Attribute. 6. Rename the attribute to StoreNumber. 7. Repeat steps 5 and 6 to create four more attributes under the Detail record and name them as follows: Employee, OrderNumber, OrderType, and OrderDate. 8. Right-click the Items node, point to Insert Schema Node, and then click Child Record. 9. Rename the record to Item. 10. Right-click the Item node, point to Insert Schema Node, and then click Child Field Attribute. 11. Rename the attribute to Qty. 12. Repeat steps 10 and 11 to create three more attributes under the Item record and name them as follows: SKU, Price, and ExtendedPrice. 13. Right-click the SalesOrder node, point to Insert Schema Node, and then click Child Field Element. 14. Rename the element to Comment. 15. Repeat steps 13 and 14 to create two more elements under the Items record and name them OrderTotal and TermOfLoan. 16. On the File menu, click Save All. Import the Customer Information from another Schema Procedure List 1. In Solution Explorer, right-click the Messaging project, point to Add, and then click Existing Item. 2. In the Add Existing Item dialog box, browse to and add C:\AllFiles\LabFiles\Lab2\CustomerInfo.xsd. You may have noticed that the sample message contains a CustomerInfo record with several fields; the CustomerInfo schema contains all these fields. 3. In BizTalk Editor, click the <Schema> node of the SalesOrder schema. 4. In the Properties window, click the Imports property, and then click the ellipsis (…) button. 5. In the Imports dialog box, verify that XSD Import is selected from the list, and then click Add. 6. In the BizTalk Type Picker dialog box, expand Messaging, expand Schemas, click Messaging.CustomerInfo, and then click OK twice. 7. In the SalesOrder schema, click the Record node. 8. In the Properties window, click the Data Structure Type property, and then in the list, click ns0:CustomerInfo (Reference). 9. On the File menu, click Save All. Validate the Schema Procedure List 1. In Solution Explorer, right-click SalesOrder.xsd, and then click Validate Schema. You can use the Validate Schema command to determine whether a schema contains any internal inconsistencies or has other issues that might prevent it from being used effectively for processing instance messages. All schemas created by using the BizTalk Schema Editor will always be valid, but this is a good way to verify that the schemas you receive from other sources are recognizable to BizTalk. Generate a Sample Instance Procedure List 1. In Solution Explorer, click SalesOrder.xsd. 2. In the Properties window, in the Output Instance Filename box, type C:\AllFiles\LabFiles\Lab2\SalesOrder-Gen.xml. 3. In Solution Explore, right-click SalesOrder.xsd, and then click Generate Instance. A sample instance message is saved in C:\AllFiles\LabFiles\Lab2, and a link to the XML instance is shown in the Output window. Hold the CTRL key, and click the link to open the resulting XML file. Validate the Sample Instance Message Procedure List 1. Click SalesOrder.xsd, and in the Properties window, in the Input Instance Filename box, type C:\AllFiles\LabFiles\Lab2\SalesOrder1.xml 2. Right-click SalesOrder.xsd, and then click Validate Instance. The results of the instance validation are displayed in the output window. This step validates the schema against an actual XML file. Exercise 3: Creating a Flat File Schema Overview BizTalk Server can also process messages in positional or delimited formats (flat files). In this exercise, you will use the Flat File Schema Wizard to create a schema that defines the structure of flat file messages sent from the Adventure Works stores. Create the SalesOrder_FF schema Procedure List 1. In Windows Explorer, navigate to and open C:\AllFiles\LabFiles\Lab2\SalesOrder_FF_Sample.txt. 2. Examine the structure of the file, and then close Notepad. 3. In Solution Explorer, right-click the Messaging project, point to Add, and then click New Item. 4. In the Add New Item dialog box, click Flat File Schema Wizard (notice that this is different than the Flat File Schema item). 5. In the Name box, type SalesOrder_FF.xsd, and then click Add. 6. On the Welcome to the BizTalk Flat File Schema Wizard page, click Next. 7. On the Flat File Schema Information page, in the Instance file box, browse to or type C:\AllFiles\LabFiles\Lab2\SalesOrder_FF_Sample.txt. 8. In the Record name box, type SalesOrder, and then click Next. 9. On the Select Document Data page, ensure that the entire contents of the document are selected, and then click Next. 10. On the Select Record Format page, verify that By delimiter symbol is selected, and then click Next. 11. On the Delimited Record page, ensure that the Child Delimiter is set to {CR}{LF}, and then click Next. 12. On the Child Elements page, change the Element Names and Element Types as follows: Element Name Element Type OrderDetail Record CustomerInfo Record Products Record Comment Field element 13. Click Next. Define the OrderDetail Record Structure Procedure List 1. On the Schema View page, ensure that the OrderDetail record is selected, and then click Next. 2. On the Select Document Data page, ensure that the first line of content is selected (excluding the ¶« characters), and then click Next. 3. On the Select Record Format page, verify that By delimiter symbol is selected, and then click Next. 4. On the Delimited Record page, set the Child Delimiter to , (comma), and then click Next. 5. On the Child Elements page, change the Element Names and Element Types as follows: Element Name Element Type StoreNumber Field Attribute OrderNumber Field Attribute Cash_Cred Field Attribute EmployeeName Field Attribute TotalOrder Field Attribute 6. Click Next. Define the CustomerInfo Record Structure Procedure List 1. On the Schema View page, ensure that the CustomerInfo record is selected, and then click Next. 2. On the Select Document Data page, ensure that the second line (name and address) is selected (excluding the ¶« characters), and then click Next. 3. On the Select Record Format page, select By relative positions, and then click Next. 4. On the Positional Record page, click the hash mark on the ruler at positions 5, 30, 34, 59, 69 and 71, and then click Next. If you accidently click an incorrect position, click it again to remove the position marker. 5. On the Child Elements page, change the Element Names and Element Types as follows: 6. Click Next. Element Name Element Type ID Field Element CustomerName Field Element MonthsAtResidence Field Element Address Field Element Town Field Element State Field Element ZipCode Field Element Define the Products Record Procedure List 1. On the Schema View page, ensure that the Products record is selected, and then click Next. 2. On the Select Document Data page, ensure that the third line (products) is selected (excluding the ¶« characters), and then click Next. 3. On the Select Record Format page, verify that By delimiter symbol is selected, and then click Next. 4. On the Delimited Record page, set the Child Delimiter to , (comma). 5. Check the Record has a tag identifier check box, in the Tag box, type PRODUCTS, and then click Next. 6. On the Child Elements page, in the first row, change the Element Name to Product, and change the Element Type to Repeating record. In the second row, change the Element Type to Ignore, and then click Next. Define the Product Record Procedure List 1. On the Schema View page, ensure that Product is selected, and then click Next. 2. On the Select Document Data page, ensure the first Product record is selected (“PRODUCT|1|75…|200.00”), excluding all commas, and then click Next. 3. On the Select Record Format page, click By delimiter symbol, and then click Next. 4. Set the Child delimiter to | (pipe), check the Record has a tag identifier box, enter PRODUCT in the Tag field, and then click Next. 5. On the Child Elements page, change the Element Names and Element Types as follows: Element Name Element Type Quantity Field Attribute ItemNumber Field Attribute PriceEach Field Attribute 6. Click Next. 7. Click Finish. 8. On the File menu, click Save All. Validate the Sample Instance Message Procedure List 1. In Solution Explorer, click SalesOrder_FF.xsd, then select the Input Instance Filename field in the Properties window. Notice that the file is the same as the sample instance used to generate the schema with the Flat File Schema Wizard. 2. Right-click SalesOrder_FF.xsd, and then click Validate Instance. The results of the instance validation are displayed in the output window. This step validates the schema against sample a flat file. 3. In the Output window, hold CTRL and click the link to the right of Validation generated XML output to view the XML representation of the flat file instance. Exercise 4: Generating a Schema from an XML Message Instance Overview BizTalk can generate a schema based on an existing XML message instance. In this exercise, you will generate a schema based on a sample loan application message. Install the Well-Formed XML Schema Generator Procedure List 1. In Windows Explorer, navigate to C:\Program Files (x86)\Microsoft BizTalk Server 2010\SDK\Utilities\Schema Generator, and then double-click InstallWFX.vbs. A command window will appear briefly as the VB script is executed. Create the LoanApp Schema Procedure List 1. In Windows Explorer, browse to and open C:\AllFiles\LabFiles\Lab2\LoanApp_Sample.xml. This is a sample of the message that is evaluated against a set of business rules to automatically approve or deny a loan application. 2. Close Internet Explorer. 3. In Solution Explorer, right-click the Messaging project, point to Add, and then click Add Generated Items. 4. In the Add Generated Items dialog box, in the Categories pane, click the Generate Schemas icon, then click Add. 5. In the Generate Schemas dialog box, in the Document type list, click Well-Formed XML, in the Input file box, browse to C:\AllFiles\LabFiles\Lab2\LoanApp_Sample.xml, click Open, and then click OK. 6. In Solution Explorer, verify that a LoanApp_Sample schema, which represents the sample message, has been created. 7. Rename LoanApp_Sample.xsd to LoanApp.xsd. 8. Click LoanApp.xsd, and then in the Properties window, type LoanApp in the Type Name box. 9. Save and Close the AdvWorks solution.