Getting Started with Adobe After Effects - Part 6: Motion Blur
Ask
Ask questions, discuss or help others by answering
Related Posts · View All
SQL Server 142
TSQL 76
SSRS 70
SSIS 66
XML 54

Top Categories · View All
SQL Server 142
TSQL 76
SSRS 70
SSIS 66
XML 54

Do SQLXML support choice element?

Aug 11 2011 12:00AM by Gaurang Patel   

Is there a known issue with SQLXML and xs:choice element? For example if I have an element embeded inside a element, SQLXML does not output those embeded elements. I am Using SQLXML 4.

Submitted under: Microsoft SQL Server · XML · XSD · XQUERY · 


Gaurang Patel
238 · 1% · 189

10 Replies

  • I dont have a ready answer, but I can take a look into it and see if I can help you. Can you post a minimal representation of your XML schema file and XML data file so that I can take a look at it?

    commented on Aug 11 2011 12:40AM
    Jacob Sebastian
    1 · 100% · 32004
  • Here is XSD schema file.

    <?xml version="1.0" encoding="utf-8" ?>
    <xsd:schema xmlns:sql="urn:schemas-microsoft-com:mapping-schema" 
                               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:annotation>
            <xsd:appinfo>
                <sql:relationship name="CustCustOrder" parent="Cust" parent-key="custInc" 
                              child="CustOrder" child-key="CustomerID" />
            </xsd:appinfo>
        </xsd:annotation>
        <xsd:element sql:is-constant="1" name="ROOT">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element sql:relation="Cust" sql:overflow-field="OverflowColumn" 
                                    name="Customers">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name="CustomerID" type="xsd:integer" />
                                <xsd:element sql:field="Company_Name" name="CompanyName"
                                          type="xsd:string" />
                                <xsd:element name="City" type="xsd:string" />
                                <xsd:element  name="Orders" sql:relation="CustOrder" 
                                                sql:relationship="CustCustOrder" 
                                                 sql:overflow-field="OverflowColumn">
                                    <xsd:complexType>
                                        <xsd:sequence>
                                            <xsd:choice  maxOccurs="unbounded">
                                            <xsd:element name="Order"  sql:field="OrderIDEx" 
                                                             maxOccurs="unbounded">
                                                <xsd:complexType>
                                                    <xsd:simpleContent>
                                                        <xsd:extension base="xsd:string">
                                                            <xsd:attribute name="OrderID" />
                                                            <!--<xsd:attribute name="CustomerID" />-->
                                                        </xsd:extension>
                                                    </xsd:simpleContent>
                                                </xsd:complexType>
                                            </xsd:element>
                                            <xsd:element name="OrderType" type="xsd:string" 
                                                             sql:field="OrderType" />
                                                </xsd:choice>
                                        </xsd:sequence>
                                    </xsd:complexType>
                                </xsd:element>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>
    

    Here is Xml file

    <ROOT>
        <Customers>
            <CustomerID>1111</CustomerID>
            <CompanyName>Hanari Carnes</CompanyName>
            <City>NY </City>
            <Junk>garbage in overflow</Junk>
            <Orders>
                <Order OrderID="1">one </Order>
                <OrderType>Bulk</OrderType>
                <Order OrderID="2"> Two </Order>
                <OrderType>Retail</OrderType>
            </Orders>
        </Customers>
        <Customers>
            <CustomerID>1112</CustomerID>
            <CompanyName>Toms Spezialitten</CompanyName>
            <City>LA </City>
            <xyz>
                <address>111 Maple, Seattle</address>
            </xyz>
            <Orders>
                <Order OrderID="3"> three </Order>
                <OrderType>Bulk</OrderType>
            </Orders>
        </Customers>
        <Customers>
            <CustomerID>1113</CustomerID>
            <CompanyName>Victuailles en stock</CompanyName>
            <Orders>
                <Order OrderID="4"> four </Order>
                <OrderType>Bulk</OrderType>
            </Orders>
        </Customers>
    </ROOT>
    

    And Here is Table Creation SQL Statement.

    CREATE TABLE Cust
        (
          custInc INT IDENTITY(1, 1) ,
          CustomerID INT PRIMARY KEY ,
          Company_Name VARCHAR(20) NOT NULL ,
          City VARCHAR(20) DEFAULT 'Seattle' ,
          OverflowColumn XML
        )
    GO
    CREATE TABLE CustOrder
        (
          OrderID INT  ,
          OrderIDEx NVARCHAR(10) ,
          OrderType NVARCHAR(10),      
          CustomerID INT ,
          OverflowColumn XML
        )
    GO
    
    commented on Aug 11 2011 1:14AM
    Gaurang Patel
    238 · 1% · 189
  • Gaurang, Your original assumption is correct. It appears that SQLXML does not support choice elements.

    Do you have control over the XSD files so that you can modify them?

    commented on Aug 11 2011 8:20AM
    Jacob Sebastian
    1 · 100% · 32004
  • Unfortunately ,I don't have, cause We are getting XML file from another organization then we have to load in Database,we have to talk the other organization from which we getting data and then we will figure out what we have to do,Thanks for your help.

    commented on Aug 12 2011 12:00AM
    Gaurang Patel
    238 · 1% · 189
  • I was referring to the XSD file. You dont need to change the XML data you receive from the other organization. Try replacing the choice element with the following

    <xsd:element name="Order"  type="xsd:string" sql:field="OrderID" />
    <xsd:element name="OrderType" type="xsd:string" sql:field="OrderType" />
    

    and see if that imports the data correctly

    commented on Aug 12 2011 12:30AM
    Jacob Sebastian
    1 · 100% · 32004
  • I Already did that,it gives Error Like "Data mapping to column 'OrderID' was already found in the data. Make sure that no two schema definitions map to the same column",When it counters data as follows then and then it is going to throw error

    <!--Repeated entry of order and order type throws error. in below XML <Order> and <OrderType> both repated twice,
    if we  have only one entry then it will not throw error,and data insertion will be successfully -->
    <ROOT>
        <Customers>
            <CustomerID>1111</CustomerID>
            <CompanyName>Hanari Carnes</CompanyName>
            <City>NY </City>
            <Junk>garbage in overflow</Junk>
            <Orders>
                <Order OrderID="1">one </Order>
                <OrderType>Bulk</OrderType>
                <Order OrderID="2"> Two </Order>
                <OrderType>Retail</OrderType>
            </Orders>
        </Customers>
    </ROOT>
    
    commented on Aug 12 2011 2:22AM
    Gaurang Patel
    238 · 1% · 189
  • I have read Record Generation Process on BOL(Link) and i don't think it is quite possible to insert such data in such a way.we have no other option Then talking to the other organization if i am wrong.Please correct me.

    commented on Aug 12 2011 2:30AM
    Gaurang Patel
    238 · 1% · 189
  • I see your point. Now I also understand why they placed the CHOICE element in the schema. So one option I can think of is to create an XSLT transformation to re-structure the way Order and OrderType elements are placed. Basically to convert them into two attributes or child elements of a single element. Before running the import, the XSLT should run to transform the XML into a new structure.

    Is this something possible to do in your environment?

    commented on Aug 12 2011 2:36AM
    Jacob Sebastian
    1 · 100% · 32004
  • Can you please give me some Reference Link cause I am Mostly working in SQL Server ,only this week i started with XML,So can you provide me some good link so i can understand how to achieve this thing.

    Then i will be able to tell is that possible in our environment.

    commented on Aug 12 2011 3:44AM
    Gaurang Patel
    238 · 1% · 189
  • Ok, so XSLT can be used to transform an XML document from one shape to another shape. The way it work is that, you first create a XML style sheet, which is an XML document that defines the transformation rules. After the style sheet is created, you pass the style sheet and your input XML document to an XSLT processor which will transform/convert the input document based on the rules defined in the style sheet and produces the output.

    The best XSLT tutorial I could find on internet is http://www.w3schools.com/xsl/

    commented on Aug 13 2011 1:13AM
    Jacob Sebastian
    1 · 100% · 32004

Your Reply


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]