Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Im usually working with GUI applications, and so this XSD is complicated enough to seem a little foreign to me. Any help would be great! The union in the XSD is throwing me off, and google returns irrelevant information or something I am having a hard time understanding. As the deadline approaches, I need to solve this as soon as possible. I appreciate your time.

Im having trouble with this API accepting my XML. When transmitted I receive this response:

"Document supplied does not comply with the XML Schema for this resource - Reason: XML Validation failed (error) - (1826) Element '{http://www.aURL.com/api/saleDetail/v1_0}lineItem': ' ' is not a valid value of the union type '{http://www.aURL.com/api/saleDetail/v1_0}lineItemType'. "

Here is the section of the XSD that applies to creating a lineItem element:
XML
<xs:simpleType name="emptyString">
        <xs:restriction base="xs:string">
            <xs:enumeration value="" />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="priceValue">
        <xs:restriction base="xs:decimal">
            <xs:totalDigits value='10'/>
            <xs:fractionDigits value='2'/>
            <xs:minInclusive value='0'/>
            <xs:maxInclusive value='99999999.99'/>
        </xs:restriction>
    </xs:simpleType>


    <xs:simpleType name="lineItemType">
        <xs:union memberTypes="priceValue emptyString" />
    </xs:simpleType>


    <xs:element name="lineItem">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="lineItemType">
                    <xs:attribute name="quantity" type="xs:unsignedInt" use="required"/>
                    <xs:attribute name="productID" type="xs:string"/>
                    <xs:attribute name="owned" type="booleanInt"/>
                    <xs:attribute name="productName" type="xs:string"/>
                    <xs:attribute name="productCampaignResourceURL" type="resourceURI"/>
                    <xs:attribute name="lineItemStatus" type="xs:string"/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>

    <xs:element name="lineItems">
      <xs:complexType>
        <xs:sequence>
            <xs:element ref="lineItem" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>


and my rejected XML build:
XML
<lineItems>
     <lineItem id="1">
             <quantity>1</quantity>
             <productId>$productID</productId>
             <owned>0</owned>
     </lineItem>
</lineItems>

Any Ideas or Tips would be greatly appreciated!
Posted

1 solution

Hi Kevin,

Is this still an issue. I am a bit tight for time now but I may be able to assist in more detail if needs.

In your schema I had to comment out the resourceURI line, and I changed booleanInt to xs:Integer.

That done, Altova was able to use the schema and this is what it generated as a default sample:
<!--Sample XML file generated by XMLSpy v2009 sp1 (http://www.altova.com)-->
<lineitems xsi:nonamespaceschemalocation="sample.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <lineitem owned="0" productname="String" quantity="0" productid="String" lineitemstatus="String">0</lineitem>
        <lineitem owned="0" productname="String" quantity="0" productid="String" lineitemstatus="String">0</lineitem>
</lineitems>


It would look like your XML should read:
<lineitems>
     <lineitem owned="0" quantity="1" productid="productID">1</lineitem>
</lineitems>



Now on the otherhand, if we take your XML as set in stone and ask Altova to generate a schema based on that piece of XML, this is what it produces:
<!--W3C Schema generated by XMLSpy v2009 sp1 (http://www.altova.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="quantity">
                <xs:simpletype>
                        <xs:restriction base="xs:byte">
                                <xs:enumeration value="1" />
                        </xs:restriction>
                </xs:simpletype>
        </xs:element>
        <xs:element name="productId">
                <xs:simpletype>
                        <xs:restriction base="xs:string">
                                <xs:enumeration value="$productID" />
                        </xs:restriction>
                </xs:simpletype>
        </xs:element>
        <xs:element name="owned">
                <xs:simpletype>
                        <xs:restriction base="xs:byte">
                                <xs:enumeration value="0" />
                        </xs:restriction>
                </xs:simpletype>
        </xs:element>
        <xs:element name="lineItems">
                <xs:complextype>
                        <xs:sequence>
                                <xs:element ref="lineItem" />
                        </xs:sequence>
                </xs:complextype>
        </xs:element>
        <xs:element name="lineItem">
                <xs:complextype>
                        <xs:sequence>
                                <xs:element ref="quantity" />
                                <xs:element ref="productId" />
                                <xs:element ref="owned" />
                        </xs:sequence>
                        <xs:attribute name="id" use="required">
                                <xs:simpletype>
                                        <xs:restriction base="xs:byte">
                                                <xs:enumeration value="1" />
                                        </xs:restriction>
                                </xs:simpletype>
                        </xs:attribute>
                </xs:complextype>
        </xs:element>
</xs:schema>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900