XML is used to describe data. XML is derived from SGML and possesses some qualities of other markup languages, like HTML. However, XML is extensible because its tags are user-defined, making it ideal for exchanging data in a structure that is mutually intelligible to two or more communicating applications.
The following isql query to the pubs2 database finds information on discounts:
1> select * from discounts 2> go
This query produces the following result set:
discounttype stor_id lowqty highqty discount --------------------- ------- ------ ------- --------- Initial Customer NULL NULL NULL 10.500000 Volume Discount NULL 100 1000 6.700000 Huge Volume Discount NULL 1001 NULL 10.000000 Customer Discount 8042 NULL NULL 5.000000
This result set can be represented in XML in many ways. The following is an XML representation produced by Adaptive Server Enterprise Web Services and formatted in SQLX, which is part of the ANSI standard for SQL:
<?xml version="1.0" encoding="UTF-8"> <ws xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <row> <discounttype>Initial Customer</discounttype> <discount>10.5</discount> </row> <row> <discounttype>Volume Discount</discounttype> <lowqty>100</lowqty> <highqty>1000</highqty> <discount>6.7</discount> </row> <row> <discounttype>Huge Volume Discount </discounttype> <lowqty>1001</lowqty> <discount>10.0</discount> </row> <row> <discounttype>Customer Discount</discounttype> <stor_id>8042</stor_id> <discount>5.0</discount> </row> </ws>
The initial line describes the XML version and character encoding. The remaining tags are user-defined and describe both the structure and data of the document. These user-defined tags enable documents to be customized for a specific application, such as one that uses discount information to compute prices.
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.
The following is a DTD for the previous example for discount information:
<!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="DOUBLE" /> </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:length value="40"/> </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="DOUBLE"> <xsd:restriction base="xsd:double"/> </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 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:
World Wide Web Consortium (W3C), at http://www.w3.org
W3C, Extensible Markup Language (XML), at http://www.w3.org/XML/