XML Data Reduced Schemas

[Previous] [Next]

As mentioned earlier in this chapter, BizTalk uses an XML Data Reduced schema. This schema and the schema currently defined by the W3C differ. Microsoft needed to build and release Internet Explorer 5, and it wanted to include an XML parser with Internet Explorer 5 that would work with schemas. Unfortunately, the W3C schema standard was not completed at the time Microsoft was developing Internet Explorer 5. Therefore, Microsoft used the temporary schema XDR. The XDR schema is based on a 1998 proposal to the W3C and can be found at http://www.w3.org/TR/1998/NOTE-XML-data-0105. Many similarities exist in the XDR and the W3C schemas, but there are also differences. The primary difference is that the two schemas use different keywords and XDR has less functionality.

The following code shows a sample DTD for the BizTalk schema.

 <!ENTITY % dataTypes "(bin.base64 | bin.hex | boolean | char | date | dateTime | dateTime.tz |fixed.14.4 | float | int | number | time | time.tz | i1 | i2 | i4 | r4 | r8 | ui1 | ui2 | ui4 |uri | uuid | entity | entities | enumeration | id | idref | idrefs | nmtoken | nmtokens | notation | string)"> <!ENTITY % elementNamespace "urn:schemas-microsoft-com:xml-data"> <!ENTITY % dataNamespace "urn:schemas-microsoft-com:datatypes"> <!ELEMENT Schema (AttributeType+, ElementType+, description)> <!ATTLIST Schema xmlns CDATA %elementNamespace; xmlns:dt CDATA %dataNamespace; name CDATA #REQUIRED > <!ELEMENT ElementType (AttributeType, attribute, element+, datatype, description, group)> <!ATTLIST ElementType order (one | seq | many) many content (empty | textOnly | eltOnly | mixed) mixed dt:type %dataTypes; #IMPLIED model (open | closed) open name ID #REQUIRED > <!ELEMENT AttributeType (datatype, description)> <!ATTLIST AttributeType name ID #REQUIRED default CDATA #REQUIRED dt:type (entity | entities | enumeration | id | idref | idrefs | nmtoken | nmtokens | notation | string) #IMPLIED dt:values CDATA #IMPLIED required (yes | no) #IMPLIED > <!ELEMENT attribute (description)> <!ATTLIST attribute type CDATA #REQUIRED default CDATA #IMPLIED required (yes | no) #IMPLIED> <!ELEMENT element (description)> <!ATTLIST element type CDATA #REQUIRED minOccurs (0 | 1) #IMPLIED maxOccurs (1 | *) #IMPLIED> <!ELEMENT description () #PCDATA> <!ELEMENT datatype ()> <!ATTLIST datatype dt:type %dataTypes; #REQUIRED> <!ELEMENT group(element, description)> <!ATTLIST group order (one | seq | many) #REQUIRED minOccurs (0 | 1) 1 maxOccurs (1 | *) 1> 

Let's look at each of the elements contained in BizTalk schemas and see how they are used.

The description Element

A description element can be used in an AttributeType, an ElementType, a Schema, a group, an element, or an attribute element. The description element contains a description of the element. A typical description element might look like this:

 <description>This document is a purchase order for Northwind Traders. </description> 

The datatype Element

The datatype element is used to specify the data type of an element or an attribute. The datatype element uses predefined data types. The current data types are listed in the following table.

Current Data Types

Data Type Description
bin.base64

A MIME-style base64-encoded binary large object (BLOB).

bin.hex

Hexadecimal digits representing octets.

boolean

0 or 1, where 0 = "false" and 1 = "true".

char

A string, one character long.

date

A date in a subset ISO 8601 format, without the time data—for example, "2000-11-05".

dateTime

A date in a subset ISO 8601 format, with an optional time and no optional zone—for example, "2000-07-07T18:39:09". Fractional seconds can be as precise as nanoseconds.

dateTime.tz

A date in a subset ISO 8601 format, with an optional time and an optional zone—for example, "2000-04-07T18:39:09-08:00". Fractional seconds can be as precise as nanoseconds.

fixed.14.4

The same as number, but no more than 14 digits to the left of the decimal point and no more than 4 digits to the right.

float

A real number that has no limit on the number of digits; it can have a leading sign, or fractional digits, or an exponent. Punctuation is in U.S. English. Values range from 1.7976931348623157E+308 through 2.2250738585072014E-308.

int

A number, with optional sign, no fractions, and no exponent.

number

A number that has no limit on digits; it can have a leading sign, fractional digits, or an exponent. Punctuation is in U.S. English. Values have same range as the most significant number, r8—that is, 1.7976931348623157E+308 through 2.2250738585072014E-308.

time

A time in a subset ISO 8601 format, with no date and no time zone—for example, "08:15:27".

time.tz

A time in a subset ISO 8601 format, with no date but an optional time zone—for example, "08:1527-05:00"

i1

An integer represented in one byte—that is, a number with an optional sign, no fractions, and no exponent—for example, "1, 127, -128".

i2

An integer represented in one word—that is, a number with an optional sign, no fractions, and no exponent—for example, "1, 703, -32768".

i4

An integer represented in four bytes—that is, a number with an optional sign, no fractions, and no exponent—for example, "1, 703, -32768, 148343,-1000000000".

r4

A real number, with no limit on digits. Can potentially have a leading sign,fractional digits, and optionally an exponent. Punctuation is in U.S. English. Values range from 3.40282347E+38F through 1.17549435E-38F.

r8

The same as float—that is, a real number that has no limit on the number of digits. Can have a leading sign, fractional digits, or an exponent. Punctuation is in U.S. English. Values range from 1.7976931348623157E+308 through 2.2250738585072014E-308.

ui1

An unsigned integer—that is, an unsigned number with no fractions and no exponent—for example, "1,255".

ui2 An unsigned integer represented in two bytes—that is, an unsigned number with no fractions and no exponent—for example, "1,255,65535".
ui4 An unsigned integer represented in four bytes—that is, an unsigned number—with no fractions and no exponent—for example, "1,703,3000000000".
uri A URI—for example, "urn:schemas-microsoft-com:Office9".
uuid Hexadecimal digits representing octets, optionally embedded with hyphens that are ignored—for example, "333C7BC4-460F-11D0-BC04-0080C7055A83".

The datatype element has one attribute: dt:type. The dt:type attribute can be set to one of the values in this table.

The datatype element can be used as shown here:

 <datatype dt:type=="char"/> 

The AttributeType Element

Declaring attributes in BizTalk schemas is a two-step process. First, you must define the attribute using the AttributeType element. Second, you associate this attribute with an element using the attribute element. If the AttributeType element is declared as a child element of the Schema element, the AttributeType element will have document-level scope. If the AttributeType element is a child element of an ElementType element, it has local scope to that element. This scenario is similar to the W3C standard.

The AttributeType element can have two child elements: description and datatype. The datatype element can be used interchangeably with the dt:type attribute. For attributes, the Microsoft XML parser can use only the following data types: entity, entities, enumeration, id, idref, idrefs, nmtoken, nmtokens, notation, and string. You can use the dt:values attribute to list the possible values for an enumerated type when dt:type is set to enumeration.

The value of the default attribute is the default value for the attribute. If dt:type is set to enumeration, the value of the default attribute must be one of the values listed in dt:values.

The name attribute specifies the name of the AttributeType element; it will be used to reference the AttributeType element. The required attribute indicates whether the attribute is required.

An example of an AttributeType declaration is shown here:

 <AttributeType name="colors" dt:type="enumeration" dt:values="red green"/> <AttributeType name="pageCount" dt:type="int"/> 

The element Element

The element element is used to declare child elements of an element. Thus, the element element is always a child element of either an ElementType element (which defines elements) or a group element. Just as you could for the element element in the W3C schema, you can define the number of occurrences of an element child element.

With BizTalk schemas, you will also use the minOccurs and maxOccurs attributes. In this case, minOccurs can only be 0 or 1. If minOccurs is 0, the element is optional; if it is 1, the element must occur once. The maxOccurs attribute can only be 1 or an asterisk (*). If maxOccurs is 1, the element can appear at most once; if it is *, the element can appear an unlimited number of times. This is different from the W3C schema, which allows any value to be assigned to minOccurs and maxOccurs.

The group Element

The BizTalk group element is similar to the group element of the W3C schema, but unlike the group element defined in the W3C standard, the BizTalk group element cannot be a child element of the schema element. This means that you cannot have document scope group elements. A group element can be used only to group elements within an element declaration—for example, within an ElementType declaration. One of the most useful features of the group element is that it can be used to define a sequence for the child elements of an element.

The group element contains element child elements. The sequence of the child elements can be specified by using the group element's order attribute. If the order attribute is set to one, there can only be one instance of each element in the group. The one value is equivalent to the pipe (|) symbol in a DTD. When the order attribute is set to seq, the elements must appear in the order in which they are declared. Using the seq value is the same as using parentheses and commas in a DTD. The many value indicates that the child elements can appear in any order. The minOccurs and maxOccurs attributes work the same as their counterparts in the element element. We will look at some examples of groups in the section "The ElementType Element" later in this chapter.

The Schema Element

Because the Schema element will be included within the body of the BizTalk document, it cannot really be considered a root element. Therefore, instead of calling the Schema element the root element, we will call it the document element—that is, the highest level element of the BizTalk document. The Schema element indicates the start of a schema definition.

Two namespace attributes should be associated with the Schema element. The first is urn:schemas-microsoft-com:xml-data. This namespace is used by applications such as the Internet Explorer 5 XML parser as a processing instruction to identify the Schema elements defined in the sample DTD at the beginning of this section. This is the default namespace, so you do not have to prefix all the Schema element names with a namespace name. The second namespace attribute is urn:schemas-microsoft-com:datatypes. This namespace is used by applications to include all the data types associated with schemas. The data types listed in the dataTypes entity in the sample DTD are the currently allowable data types for elements.

Our sample DTD allows the following elements to be child elements of the Schema element: AttributeType, ElementType, and description. The description child element can occur once and provides a text description of the business document. Because the AttributeType child element belongs to the Schema element, this element is similar to the attributeGroup element of the W3C schema in that it represents an element with document scope. Unlike the attributeGroup element, however, the AttributeType element allows you to define only a single type of attribute instead of a group of attributes. The ElementType child element is equivalent to the element element in the W3C schema and is used to define elements.

An example of a Schema element is shown here:

 <Schema name="NorthwindSchema" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">  </Schema> 

The ElementType Element

The ElementType element is used to define an element type. The ElementType element can have the following child elements: attribute, AttributeType, datatype, description, element, and group. The AttributeType element will create local definitions for the attribute element, the attribute element will be used to define attributes associated with the element, and the element element will be used to define child elements of the element. The datatype element can define an element as being any of the data types listed in the table in the section "The datatype Element."

You can also declare an element as a certain type by using the dt:type attribute as one of the attributes of the ElementType element. In addition to this attribute, the ElementType element also has the model, order, content, and name attributes. The model attribute is used to indicate whether an element can contain content defined only in the content model or can contain content not specified in the content model. A content model is a pattern that you set up to declare what child element types are allowed inside an element and the order of those child elements. If the model attribute is set to open, the default value, the element can contain content that is not specified in the content model. In this case, this attribute is similar to the any type in the W3C standard. If the model attribute is set to closed, the element can contain only content that is defined in the content model.

The order attribute functions the same as its counterpart in the group element. The content attribute can be empty when there is no content, textOnly when the content is only text, eltOnly when the content is only elements, and mixed when the content is a mixture of elements and text. The name attribute defines the name of the element.

NOTE
If the model attribute is open and the content attribute is textOnly, the content can be both text and unnamed elements.

An example of the ElementType element is shown here:

 <Schema name="NorthwindSchema" xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes"> <AttributeType name="colors" dt:type="enumeration" dt:values="red green"/> <ElementType name="3Dimage" content="eltOnly" model="closed"> <attribute type ="colors"/> <AttributeType name="width" dt:type="int"/> <attribute type = "width"/> <group order="seq"> <element type="x"/> <element type="y"/> <element type="z"/> </group> </ElementType>  </Schema> 

This schema declares a document scope AttributeType element named colors that is defined as an attribute in the 3Dimage element by using the attribute element. A local declaration of an AttributeType element named width is also defined as an attribute in the 3Dimage element by using the attribute element. This pairing of a local AttributeType element followed by an attribute element that uses the AttributeType element as an attribute is the most common way to use these elements. The schema also uses a group element to sequentially group elements.

The following example demonstrates a valid use of this schema:

 <3Dimage color="blue" width="5"> <x>1</x> <y>3</y> <z>6</z> </3Dimage> 

If you change the value of the order attribute in the group element to one in the schema, this example would be invalid; but the following example is valid with the changed schema:

 <3Dimage color="blue" width="5"> <x>1</x> </3Dimage> 

You can also declare an ElementType element as a data type. The following declaration creates an integer element named quantity:

 <ElementType name= "quantity" dt:type="int"/> 

This element could also be declared as shown here:

 <ElementType name= "quantity" > <datatype dt:type="int"/> </ElementType> 



Developing XML Solutions
Developing XML Solutions (DV-MPS General)
ISBN: 0735607966
EAN: 2147483647
Year: 2000
Pages: 115
Authors: Jake Sturm

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net