IBM®
Skip to main content
    United States [change]      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     
     
  XML on TPF: A Short Tutorial IBM

XML on TPF: A Short Tutorial — Page 5 of 14
Create a Sample XML Schema

Using an XML Schema is another method of defining the acceptable tags for an XML document. An XML Schema is written in XML syntax and typically resides in a file separate from the XML document. The XML document must refer to the specific XML Schema document on which it is written.

This sample XML Schema is less focused on an actual implementation and more focused on demonstrating the various ways to write XML data:

  • Elements:
                    <xs:element name="FirstName"/>
                    
  • Nested Elements:
    		<xs:element name="FormOfPayment">
    		  <xs:complexType>
    		    <xs:sequence>
    		      <xs:element name="ccIssuer"/>
    		      <xs:element ref="ccNumber"/>
    		      <xs:element name="ccExpiration"/>
    		      </xs:sequence>
    		    </xs:complexType>
    		</xs:element>
                    
  • Attributes:
    		<xs:element name="PhoneNumber">
    		  <xs:complexType>
    		    <xs:attribute name="countryCode" />
    		    <xs:attribute name="areaCode" />
    		    <xs:attribute name="pNumber"/>
    		  </xs:complexType>
    		</xs:element>
                    

An XML Schema document must have a namespace declaration. For example:

<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema">

Before continuing, do the following:
  1. Open the sample XML Schema in another browser window.
  2. See how elements, nested elements, and attributes are used. To help understand the differences between an XML Schema and DTD, consider comparing this file with the sample DTD that you saved previously in the tutorial.
  3. Click File --> Save As.
  4. Save the file in C:\xmltut as pnrs.xsd. The default file name may be pnrs.xsd.txt or pnrs.xsd.html. If this is true, ensure that you remove the .txt or .html extension. (The XML document on the next page calls this XML Schema, so the name must match exactly.)
  5. Close the window by clicking the X in the upper-right corner.
Once you have saved the XML document, you are ready to continue.

For More Information
See the TPF XML User's Guide for the following:

  • A list of books and Web sites for learning about writing XML documents
  • More information about well-formed and valid XML documents.

PreviousNext

Back to the Beginning
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14

 

Close This Window.

 

    About IBM Privacy Contact