Schema of a XML file



I have an issue understanding the way my output of the query I am running :



SELECT [Customer].custid AS [custid],
[Customer].companyname AS [companyname],
[Order].orderid AS [orderid],
[Order].orderdate AS [orderdate]
FROM Sales.Customers AS [Customer]
INNER JOIN Sales.Orders AS [Order]
ON [Customer].custid = [Order].custid
WHERE 1 = 2
FOR XML AUTO, ELEMENTS,
XMLSCHEMA('TK461-CustomersOrders');


This is the output :



<xsd:schema targetNamespace="TK461-CustomersOrders" xmlns:schema="TK461-CustomersOrders" xmlns:xsd="http://ift.tt/tphNwY" xmlns:sqltypes="http://ift.tt/1o3ANS9" elementFormDefault="qualified">
<xsd:import namespace="http://ift.tt/1o3ANS9" schemaLocation="http://ift.tt/1o3ANSc" />
<xsd:element name="Customer">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="custid" type="sqltypes:int" />
<xsd:element name="companyname">
<xsd:simpleType>
<xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52">
<xsd:maxLength value="40" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element ref="schema:Order" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Order">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="orderid" type="sqltypes:int" />
<xsd:element name="orderdate" type="sqltypes:datetime" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>


I've spent more than 4 hours searching about these without any result.


I am not able to understand the functionality behind :


targetNamespace - why do I need it if I am using xmlns and I am using prefixes to all my other elements


xmlns:schema - Why do I need a schema for the namespace ? I am already defining one for the XSD, which I use as a prefix to my elements already


importing the namespaces : why do I need that if I am already defining the namespaces previously ?


There is no place where I can find some details about these so I can understand them, there's only explanation for simple prefixing and namespacing a prefix, but I've yet to find an explanation for an XSD such as this.


I've worked very little with XSD-s and I cannot understand how these things work together Sorry for bad question, but I've wasted more than 4 hours trying to understand something easy, can't help myself with this one.


No comments:

Post a Comment