Specify this option to have the data provider generate XML output that is compatible with SQL Server 2005 as well as the Dataset component in the .Net framework. This means that the data can be directly put into SQL Server 2005.
See SQL Server (and W3C) documentation for more information on this.
Notes: Dataset.ReadXml(XmlReadMode.ReadSchema) is the preferred way to import the query results into a DataTable.
XMLSCHEMA takes an optional argument, the target namespace URI. Here are examples that clarify how this works:
Examples:
- <Root>
- <xsd:schema … targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet1" …>
<xsd:import … />
- <xsd:element name="Data">
+ <xsd:complexType>
- <!--
-->
<xsd:attribute name="Application_x0020_Number" type="sqltypes:int" />
<xsd:attribute name="Serial_x0020_Number" type="sqltypes:int" />
<xsd:attribute name="Batch_x0020_Number" type="sqltypes:int" />
<xsd:attribute name="Date_x0020_Scanned" type="sqltypes:date" />
<xsd:attribute name="Document_x0020_Number" type="sqltypes:int" />
- <xsd:attribute name="Edit_x0020_Status">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Edit Status]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Altered_x0020_Since_x0020_Scanned">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Altered Since Scanned]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Grid_x0020_Error_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Grid Error Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Mark_x0020_Threshold" type="sqltypes:int" />
<xsd:attribute name="Mark_x0020_Discrimination" type="sqltypes:int" />
- <xsd:attribute name="Scanning_x0020_Release_x0020_Level">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Scanning Release Level]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Output_x0020_Stacker">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Output Stacker]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Worst_x0020_Mark_x0020_Intensity">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Worst Mark Intensity]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Total_x0020_Invalid_x0020_Responses" type="sqltypes:int" />
<xsd:attribute name="Run_x0020_Number" type="sqltypes:int" />
- <xsd:attribute name="Key_x0020_Record_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Key Record Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Record_x0020_Scored_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Record Scored Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Sheet_x0020_Compile_x0020_Edit_x0020_Flags">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Sheet Compile Edit Flags]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Record_x0020_Marked_x0020_Deleted_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Record Marked Deleted Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Record_x0020_Converted_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Record Converted Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="IFD_x0020_Offset" type="sqltypes:int" />
<xsd:attribute name="Count_x0020_Of_x0020_Clips" type="sqltypes:int" />
<xsd:attribute name="Length" type="sqltypes:int" />
<xsd:attribute name="Offset" type="sqltypes:int" />
<xsd:attribute name="Clips" type="sqltypes:binary" />
- <xsd:attribute name="ASCII">
- <xsd:simpleType sqltypes:sqlTypeAlias="[ASCII]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Raw">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Raw]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="ROWID">
- <xsd:simpleType sqltypes:sqlTypeAlias="[ROWID]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<Data xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1" Application_x0020_Number="701" Serial_x0020_Number="1" … ROWID="000001" />
You can specify a target namespace URI as an argument to xmlschema: in the following example, ‘MyData’ exists in the namespace ‘MyUri’. Each row has a default namespace attribute declaration for the specified target namespace URI.
Select * from master for xml raw ('MyData'), root ('MyRoot'),xmlschema ('MyUri')
Partial output appears under:
- <MyRoot>
+ <xsd:schema … targetNamespace="MyUri" …>
<xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" />
- <xsd:element name="MyData">
- <xsd:complexType>
- <!--
-->
<xsd:attribute name="Application_x0020_Number" type="sqltypes:int" />
<xsd:attribute name="Serial_x0020_Number" type="sqltypes:int" />
<xsd:attribute name="Batch_x0020_Number" type="sqltypes:int" />
<xsd:attribute name="Date_x0020_Scanned" type="sqltypes:date" />
<xsd:attribute name="Document_x0020_Number" type="sqltypes:int" />
- <xsd:attribute name="Edit_x0020_Status">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Edit Status]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Altered_x0020_Since_x0020_Scanned">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Altered Since Scanned]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Grid_x0020_Error_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Grid Error Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Mark_x0020_Threshold" type="sqltypes:int" />
<xsd:attribute name="Mark_x0020_Discrimination" type="sqltypes:int" />
- <xsd:attribute name="Scanning_x0020_Release_x0020_Level">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Scanning Release Level]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Output_x0020_Stacker">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Output Stacker]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Worst_x0020_Mark_x0020_Intensity">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Worst Mark Intensity]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="Total_x0020_Invalid_x0020_Responses" type="sqltypes:int" />
<xsd:attribute name="Run_x0020_Number" type="sqltypes:int" />
- <xsd:attribute name="Key_x0020_Record_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Key Record Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Record_x0020_Scored_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Record Scored Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Sheet_x0020_Compile_x0020_Edit_x0020_Flags">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Sheet Compile Edit Flags]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Record_x0020_Marked_x0020_Deleted_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Record Marked Deleted Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Record_x0020_Converted_x0020_Flag">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Record Converted Flag]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="IFD_x0020_Offset" type="sqltypes:int" />
<xsd:attribute name="Count_x0020_Of_x0020_Clips" type="sqltypes:int" />
<xsd:attribute name="Length" type="sqltypes:int" />
<xsd:attribute name="Offset" type="sqltypes:int" />
<xsd:attribute name="Clips" type="sqltypes:binary" />
- <xsd:attribute name="ASCII">
- <xsd:simpleType sqltypes:sqlTypeAlias="[ASCII]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="Raw">
- <xsd:simpleType sqltypes:sqlTypeAlias="[Raw]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
- <xsd:attribute name="ROWID">
- <xsd:simpleType sqltypes:sqlTypeAlias="[ROWID]">
<xsd:restriction base="sqltypes:nchar" />
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<MyData xmlns="MyUri" Application_x0020_Number="701" Serial_x0020_Number="1" … />