3

I'm trying to figure out how to use SQLXML bulk load for a rather complicated XML schema I have no control over (It's nominally a "standard"). A small example would be:

<RootElement>
    <id root="e5404218-250a-4454-98d5-f9feee8a3589" />
    <code code="93000" />
    <time>
        <low value="20140221095400.000" />
        <high value="20140221095410.000" />
    </time>
</RootElement>

With an AXSD schema of:

<?xml version="1.0"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
    <xs:element name="RootElement" sql:relation="re" >
        <xs:complexType>
            <xs:sequence>
                <xs:element name="id" maxOccurs="1" minOccurs="1">
                    <xs:complexType>
                        <xs:attribute name="root" type="xs:ID" sql:field="id" sql:identity="useValue"/>
                    </xs:complexType>
                </xs:element>
                <xs:element name="code" minOccurs="1" maxOccurs="1">
                    <xs:complexType>
                        <xs:attribute name="code" type="xs:long"/>
                    </xs:complexType>
                </xs:element>
                <xs:element name="time" type="timeRange"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="timeRange">
        <xs:choice>
            <xs:sequence>
                <xs:element name="low">
                    <xs:complexType>
                        <xs:attribute name="value" type="xs:string"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:sequence>
                <xs:element name="high">
                    <xs:complexType>
                        <xs:attribute name="value" type="xs:string"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:choice>
    </xs:complexType>
</xs:schema>

My sticking point seems to come from the ID being attached to an attribute on an element, instead of an element value, as no matter what tweaks I use, I get the error Schema: relationship expected on 'id'.. There really is no relationship there, it's just a container, since the committee that designed this schema seems to have really taken a liking to attributes.

All examples I find deal with the values being element content instead of attributes. This includes decorating the element with sql:is-constant (Constant element cannot have attributes), and various permutations of the sql:relation element.

The only option I could think of is to have a pre-processing step that makes attributes child elements, and base the schema on that, but that seems kind of hacky.

Any suggestions on how to convince SQLXML to do my bidding?

Matt Sieker
  • 9,349
  • 2
  • 25
  • 43

0 Answers0