XML document structure

The user-defined elements and their arrangement in a well-formed XML document is defined either by a Document Type Definition (DTD) or an XML schema.

Following is a DTD for the previous example for discount information:

<!DOCTYPE ws [ 
<!ELEMENT ws (row*)>
<!ELEMENT row (discounttype, stor_id?, lowqty?, highqty?, discount)>
<!ELEMENT discounttype (#PCDATA)>
<!ELEMENT stor_id (#PCDATA)>
<!ELEMENT lowqty (#PCDATA)>
<!ELEMENT highqty (#PCDATA)>
<!ELEMENT discount (#PCDATA)>
]>

The following is part of an XML schema for the previous example for discount information:

<xsd:schema
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:sqlxml="http://www.iso-
      standards.org/mra/9075/sqlx">
   <xsd:import      namespace="http://www.w3.org/2001/XMLSchema"
      schemaLocation="http://www.iso-
         standards.org/mra/9075/sqlx.xsd" />
   <xsd:complexType name="RowType.ws">
      <xsd:sequence>
         <xsd:element name="discounttype"
          type="VARCHAR_40" />
         <xsd:element name="stor_id" type="CHAR_4" 
          minOccurs="0" maxOccurs="1"/>
         <xsd:element name="lowqty" type="SMALLINT"
          minOccurs="0" maxOccurs="1"/>
         <xsd:element name="highqty" type="SMALLINT"
          minOccurs="0" maxOccurs="1"/>
         <xsd:element name="discount" type="FLOAT" />
      </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="TableType.ws">
      <xsd:sequence>
         <xsd:element name="row" type="RowType.ws"
          minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:simpleType name="VARCHAR_40">
      <xsd:restriction base="xsd:string">
         <xsd:maxLength value="40"/>
      </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="VARCHAR_4">
      <xsd:restriction base="xsd:string">
         <xsd:maxLength value=”4”/>
      </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="SMALLINT">
      <xsd:restriction base="xsd:integer">
         <xsd:maxInclusive value="32767"/>
         <xsd:minInclusive value="-32768"/>
      </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="FLOAT">
      <xsd:restriction base="xsd:float"/>
   </xsd:simpleType>
   <xsd:element name="ws" type="TableType.ws"/>
</xsd:schema>

An XML schema or DTD can be included as part of the XML document they describe or be referenced as separate files. The respective file suffixes for an XML schema and a DTD are .xsd and .dtd.

For more detailed information on XML, refer to the following documents: