The following SQL result set has 5 columns, whose datatypes are respectively varchar(3), numeric(3,1), varbinary(2), numeric(3,1), and numeric(3,2).
select 'abc', 12.3, 0x00, 45.6, 7.89 --- ------ ---- ------ ------ abc 12.3 0x00 45.6 7.89
The SQLX-XML result set for this data is:
select forxmlj("select 'abc', 12.3, 0x00, 45.6, 7.89", "") ------------------------------------------------------ <resultset xmlns:xsi="http://www.w3.org/2001 /XMLSchema-instance"> <row> <C1>abc</C1> <C2>12.3</C2> <C3>00</C3> <C4>45.6</C4> <C5>7.89</C5> </row> </resultset>
The SQLX-XML schema describing this document is:
select forxmlschemaj("select 'abc', 12.3, 0x00, 45.6, 7.89", "") ------------------------------------------ <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.resultset"> <xsd:sequence> <xsd:element name="C1" type="VARCHAR_3" /> <xsd:element name="C2" type="NUMERIC_3_1" /> <xsd:element name="C3" type="VARBINARY_2" /> <xsd:element name="C4" type="NUMERIC_3_1" /> <xsd:element name="C5" type="NUMERIC_3_2" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="TableType.resultset"> <xsd:sequence> <xsd:element name="row" type="RowType.resultset" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:simpleType name="VARCHAR_3"> <xsd:restriction base="xsd:string"> <xsd:length value="3"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="NUMERIC_3_1"> <xsd:restriction base="xsd:decimal"> <xsd:totalDigits value="3"/> <xsd:fractionDigits value="1"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="VARBINARY_2"> <xsd:restriction base="xsd:hexBinary"> <xsd:length value="2"/> </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="NUMERIC_3_2"> <xsd:restriction base="xsd:decimal"> <xsd:totalDigits value="3"/> <xsd:fractionDigits value="2"/> </xsd:restriction> </xsd:simpleType> <xsd:element name="resultset" type="TableType.resultset"/> </xsd:schema>
This XML schema has five components:
In the last part of this sample XML schema are three xsd:simpleTypeelements, which declare simple XML types for the four distinct datatypes in the XML document. These simpleType declarations specify the XML base type for each type, and specify xsd:restriction elements that define the length characteristics of the SQL data. Each simpleType declarations has an XML name: VARCHAR_3, NUMERIC_3_1, VARBINARY_2, and NUMERIC_3_2.
The XML schema contains a separate xsd:simpleType for each distinct attribute combination of SQL datatype, length, and precision. For instance, there are separate types for NUMERIC_3_1 and NUMERIC_3_2. However, there is only one xsd:simpleType declaration for NUMERIC_3_1, even though there are two columns with that type. The element declarations for those columns both reference the same simple type name, NUMERIC_3_1.
The first part of the example XML schema is an xsd:complexType for the row type, which defines an element for each column. Each of those element declarations specifies the datatype of the element with the simple type name described above.
The middle part of the example XML schema is an xsd:complexType for the result set, declaring it to be a sequence of row elements whose type is the previously defined row type.
Finally, the very last line of the example XML schema declares the root element of the result set document.