Note that there are some explanatory texts on larger screens.

plurals
  1. POReturn Nested XMLSCHEMA from SQL Server 2005
    primarykey
    data
    text
    <p>Is it possible to return a nested XMLSCHEMA from SQL Server 2005?</p> <p>Right now I have a stored procedure to generate a NESTED select query that can be executed to return an XML document. I do this by appending this to the end of each nested query: </p> <pre><code>FOR XML AUTO ,TYPE ,ELEMENTS </code></pre> <p>I had though by just changing this to: </p> <pre><code>FOR XML AUTO ,TYPE ,ELEMENTS, XMLSCHEMA </code></pre> <p>that I might be able to return a nested XSD document.</p> <p>What gets returned looks like an XSD with another entire XSD pasted inside, meaning each one had its own namespaces and schemaLocation. I just need them to appear as xsd:elements inside the root XSD.</p> <pre><code>SELECT Stuff, (SELECT OtherStuff FROM test2 FOR XML AUTO, TYPE, ELEMENTS, XMLSCHEMA) FROM test FOR XML AUTO, TYPE, ELEMENTS, XMLSCHEMA </code></pre> <p>This is what is returned:</p> <pre><code>&lt;xsd:schema xmlns:schema="urn:schemas-microsoft-com:sql:SqlRowSet26" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet26" elementFormDefault="qualified"&gt; &lt;xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" /&gt; &lt;xsd:element name="test" type="sqltypes:xml" /&gt; &lt;/xsd:schema&gt; &lt;test xmlns="urn:schemas-microsoft-com:sql:SqlRowSet26"&gt; &lt;Stuff&gt;Stuff&lt;/Stuff&gt; &lt;xsd:schema xmlns:schema="urn:schemas-microsoft-com:sql:SqlRowSet25" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" xmlns="" targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet25" elementFormDefault="qualified"&gt; &lt;xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" /&gt; &lt;xsd:element name="test2"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="OtherStuff" minOccurs="0"&gt; &lt;xsd:simpleType&gt; &lt;xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52"&gt; &lt;xsd:maxLength value="50" /&gt; &lt;/xsd:restriction&gt; &lt;/xsd:simpleType&gt; &lt;/xsd:element&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;/xsd:schema&gt; &lt;test2 xmlns="urn:schemas-microsoft-com:sql:SqlRowSet25"&gt; &lt;OtherStuff&gt;OtherStuff&lt;/OtherStuff&gt; &lt;/test2&gt; &lt;/test&gt; </code></pre> <p>This is what I need to be returned:</p> <pre><code>&lt;xsd:schema xmlns:schema="urn:schemas-microsoft-com:sql:SqlRowSet26" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet26" elementFormDefault="qualified"&gt; &lt;xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" /&gt; &lt;xsd:element name="test" type="sqltypes:xml" /&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="Stuff" minOccurs="0"&gt; &lt;xsd:simpleType&gt; &lt;xsd:restriction base="sqltypes:varchar"&gt; &lt;xsd:maxLength value="50"/&gt; &lt;/xsd:restriction&gt; &lt;/xsd:simpleType&gt; &lt;/xsd:element&gt; &lt;xsd:element name="test2"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="OtherStuff" minOccurs="0"&gt; &lt;xsd:simpleType&gt; &lt;xsd:restriction base="sqltypes:varchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52"&gt; &lt;xsd:maxLength value="50" /&gt; &lt;/xsd:restriction&gt; &lt;/xsd:simpleType&gt; &lt;/xsd:element&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;/xsd:schema&gt; </code></pre> <p>What SQL is returning is actually syntactically incorrect XML. There should not be two ROOT elements</p> <p>Any help will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload