Microsoft KB Archive/914596: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - ">" to ">")
 
(One intermediate revision by the same user not shown)
Line 103: Line 103:


CREATE XML SCHEMA COLLECTION unionType AS N'
CREATE XML SCHEMA COLLECTION unionType AS N'
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"  
<xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;  
     targetNamespace=&quot;MyDatabase&quot; xmlns:tn=&quot;MyDatabase&quot;&gt;
     targetNamespace=&quot;MyDatabase&quot; xmlns:tn=&quot;MyDatabase&quot;>
      
      
     &lt;xs:simpleType name=&quot;myInt&quot;&gt;
     <xs:simpleType name=&quot;myInt&quot;>
         &lt;xs:restriction base=&quot;xs:integer&quot;&gt;
         <xs:restriction base=&quot;xs:integer&quot;>
             &lt;xs:maxInclusive value=&quot;1000&quot;/&gt;
             <xs:maxInclusive value=&quot;1000&quot;/>
         &lt;/xs:restriction&gt;
         </xs:restriction>
     &lt;/xs:simpleType&gt;
     </xs:simpleType>
      
      
     &lt;xs:element name=&quot;s&quot;&gt;
     <xs:element name=&quot;s&quot;>
         &lt;xs:simpleType&gt;
         <xs:simpleType>
             &lt;xs:union memberTypes=&quot;xs:double tn:myInt&quot;/&gt;
             <xs:union memberTypes=&quot;xs:double tn:myInt&quot;/>
         &lt;/xs:simpleType&gt;
         </xs:simpleType>
     &lt;/xs:element&gt;
     </xs:element>
&lt;/xs:schema&gt;'
</xs:schema>'
go
go


Line 123: Line 123:
go
go


insert into testTable values ('&lt;tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;tn:myInt&quot;&gt;123&lt;/tn:s&gt;')
insert into testTable values ('<tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;tn:myInt&quot;>123</tn:s>')


select xmlCol from testTable
select xmlCol from testTable
Line 131: Line 131:
go</pre>
go</pre>
<p>The following is the expected result.</p>
<p>The following is the expected result.</p>
<pre class="codesample">&lt;tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;tn:myInt&quot;&gt;123&lt;/tn:s&gt;
<pre class="codesample"><tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;tn:myInt&quot;>123</tn:s>
&lt;tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;tn:myInt&quot;&gt;123&lt;/tn:s&gt;</pre>
<tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;tn:myInt&quot;>123</tn:s></pre>
<p>However, the following is the actual result.</p>
<p>However, the following is the actual result.</p>
<pre class="codesample">&lt;tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;tn:myInt&quot;&gt;123&lt;/tn:s&gt;
<pre class="codesample"><tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:type=&quot;tn:myInt&quot;>123</tn:s>
&lt;tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:p1=&quot;http://www.w3.org/2001/XMLSchema&quot; xsi:type=&quot;p1:decimal&quot;&gt;123&lt;/tn:s&gt;</pre></li></ol>
<tn:s xmlns:tn=&quot;MyDatabase&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:p1=&quot;http://www.w3.org/2001/XMLSchema&quot; xsi:type=&quot;p1:decimal&quot;>123</tn:s></pre></li></ol>





Latest revision as of 10:24, 21 July 2020

Article ID: 914596

Article Last Modified on 11/22/2007



APPLIES TO

  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Workgroup Edition





SYMPTOMS

Consider the following scenario. You specify the value of the xsi:type attribute of a union element. Then, you use XQuery to query against the XML data that contains the union element. In this scenario, the query returns the incorrect type for the union element.

CAUSE

This problem occurs because the value of the xsi:type attribute of the union element will be the primitive base type of the value. During XML serialization, the primitive base type that is actually set for the value of the xsi:type attribute is returned.

RESOLUTION

Service pack information

To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2005. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

913089 How to obtain the latest service pack for SQL Server 2005


STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was first corrected in Microsoft SQL Server 2005 Service Pack 1.

MORE INFORMATION

Steps to reproduce the problem

  1. Open SQL Server Management Studio, and then connect to the instance of SQL Server 2005.
  2. Click New Query on the toolbar.
  3. Paste the following code in the query editor, and then press F5.

    use master
    use master
    if (db_id('MyDatabase') is not null)
        drop database MyDatabase
    go
    
    create database MyDatabase
    go
    
    use MyDatabase
    go
    
    CREATE XML SCHEMA COLLECTION unionType AS N'
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="MyDatabase" xmlns:tn="MyDatabase">
        
        <xs:simpleType name="myInt">
            <xs:restriction base="xs:integer">
                <xs:maxInclusive value="1000"/>
            </xs:restriction>
        </xs:simpleType>
        
        <xs:element name="s">
            <xs:simpleType>
                <xs:union memberTypes="xs:double tn:myInt"/>
            </xs:simpleType>
        </xs:element> 
    </xs:schema>'
    go
    
    CREATE TABLE testTable ( PK int identity primary key, xmlCol XML(unionType))
    go
    
    insert into testTable values ('<tn:s xmlns:tn="MyDatabase" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="tn:myInt">123</tn:s>')
    
    select xmlCol from testTable
    go
    
    SELECT xmlCol.query('/') FROM testTable
    go

    The following is the expected result.

    <tn:s xmlns:tn="MyDatabase" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="tn:myInt">123</tn:s>
    <tn:s xmlns:tn="MyDatabase" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="tn:myInt">123</tn:s>

    However, the following is the actual result.

    <tn:s xmlns:tn="MyDatabase" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="tn:myInt">123</tn:s>
    <tn:s xmlns:tn="MyDatabase" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p1="http://www.w3.org/2001/XMLSchema" xsi:type="p1:decimal">123</tn:s>


Keywords: kbqfe kbsql2005sp1fix kbsql2005presp1fix kbsql2005xml kbexpertiseadvanced kbprb KB914596