XML/XSD Review

Previous Menu Next

Brief Review of XML and XSD

Obviously the purpose of this tutorial is not to teach you about XML and XSD; it is assumed that you are already familiar with these concepts. But a brief review of the concepts so the information is fresh in your mind as you start studying XBinder may be useful. You can feel free to skip to the next section if you wish.

XML stands for eXtensible Markup Language. It's a mechanism where data items and identifying information can be co-mingled. The identifying information is expressed as tags, which are brief data identifiers enclosed in angle brackets (<>). There is an opening tag to begin the definition of a data item or a collection of data items, and a corresponding closing tag, which consists of the identifier preceded by a forward slash (/) within the brackets. The data items are typically called elements.

The specification of an element can provide the value, or content, of the element and attributes that further define the element.

For example, consider the following stream of non-XML data about a ficticious person named John Smith:

   John Smith|12345|Objective Systems Online Store|XBinder XML Data Binding Tool|750.00
       

All we have here are five pieces of information. Is this stream describing a purchase? Is it describing a return? Or is describing something else entirely, perhaps a reseller purchase agreement between Objective Systems and a vendor? And what is the meaning of the 12345?

Now consider a possible XML stream (typically called an XML document or XML instance) for the same collection of data:

   <purchase>
     <customer number="12345">
       John Smith
     </customer>
     <store>
       Objective Systems Online Store
     </store>
     <item>
       XBinder XML Data Binding Tool
     </item>
     <price>
       750.00
     </price>
   </purchase>
   
		

From looking at the XML instance one can tell without doubt that the collection of data describes a purchase by customer John Smith (who has customer number 12345 according to the number attribute) from the Objective Systems' Online Store of an XBinder XML Data Binding Tool for the price of $750.00.

XSD stands for XML Schema Definition. It's a mechanism for defining the format and content of an XML instance. For example, an XML schema might stipulate that one particular data item, called an element, must be a text string and that another must be some type of decimal number. Similar definitions can be specified for attributes. Schemas can also define concepts like the order in which elements are to appear, whether an element can be repeated, whether one of several possible elements can appear, etc. A schema document is itself expressed using XML.

Consider the following possible schema for the above XML instance:

   <xsd:element name="purchase" type="PurchaseRecord"/>

   <xsd:complexType name="PurchaseRecord">
      <xsd:sequence>
         <xsd:element name="customer" type="CustomerType" maxOccurs="1"/>
         <xsd:element name="store" type="xsd:string" maxOccurs="1"/>
         <xsd:sequence maxOccurs="unbounded">
            <xsd:element name="item" type="xsd:string"/>
            <xsd:element name="price" type="xsd:float"/>
         </xsd:sequence>
      </xsd:sequence>
   </xsd:complexType>

   <xsd:complexType name="CustomerType">
      <xsd:simpleContent>
         <xsd:extension base="xsd:string">
            <xsd:attribute name="number" type="xsd:integer"/>
         </xsd:extensiion>
      </xsd:simpleContent>
   </xsd:complexType>
   

This schema stipulates that a purchase record must contain elements that define the customer who purchased the item(s), the store where the items were purchased, the item descriptions, and the prices of the items. Within any purchase record defined by this schema, the customer and store elements occur just once, but the item and price elements can repeat. The items must be in the order specified. The customer element has an attribute that defines the customer number.

Previous Menu Next