Creating an XML schema


The following is an example of creating an XML schema:

  1. Create an XML schema containing the elements for your purchase order. See the following sample XML schema.

    Element definition should end on the same line unless that element has a body or children. 

  2. Name the schema PurchaseOrder.xsd.

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XML Spy v4.3 U (http://www.xmlspy.com) by AR System -->
    <xs:schema targetNamespace="http://tempuri.org" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="PO" type="PurchaseOrder">
    <xs:annotation>
    <xs:documentation>Comment describing your root element
           </xs:documentation>
    </xs:annotation>
    </xs:element>
    <xs:complexType name="PurchaseOrder">
    <xs:sequence>
    <xs:element name="POID" type="xs:string"/>
    <xs:element name="CompanyName" type="xs:string"/>
    <xs:element name="Description" type="xs:string"/>
    <xs:element name="PhoneNumber" type="xs:string"/>
    <xs:element ref="Items"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="LineItem">
    <xs:sequence>
    <xs:element name="ItemName" type="xs:string"/>
    <xs:element name="Quantity" type="xs:int"/>
    <xs:element name="ItemId" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:element name="Item" type="LineItem"/>
    <xs:element name="Items">
    <xs:complexType>
    <xs:sequence>
    <xs:element ref="Item" minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>


 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*