XSD到XML的麻烦,传输与联合返回错误. [英] XSD to XML trouble, transmission returns error with union.

查看:75
本文介绍了XSD到XML的麻烦,传输与联合返回错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用GUI应用程序,因此此XSD非常复杂,对我来说似乎有点陌生.任何帮助将是巨大的! XSD中的工会让我失望了,Google返回了不相关的信息或我很难理解的信息.随着期限的临近,我需要尽快解决.感谢您的宝贵时间.

我在使用此API接受我的XML时遇到麻烦.传输后,我收到此响应:

提供的文档不符合该资源的XML架构-原因:XML验证失败(错误)-(1826)元素"{http://www.aURL.com/api/saleDetail/v1_0}lineItem": ""不是联合体类型"{http://www.aURL.com/api/saleDetail/v1_0}lineItemType"的有效值."

这是XSD的适用于创建lineItem元素的部分:

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:

<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>



和我拒绝的XML版本:



and my rejected XML build:

<lineItems>
     <lineItem id="1">
             <quantity>1</quantity>
             <productId>$productID</productId>
             <owned>0</owned>
     </lineItem>
</lineItems>


推荐答案

productID < > < 拥有的 > 0 < /owned > < /lineItem > < /lineItems >
productID</productId> <owned>0</owned> </lineItem> </lineItems>


任何想法或技巧将不胜感激!


Any Ideas or Tips would be greatly appreciated!


凯文,

这仍然是一个问题.我现在的时间有点紧张,但是如果需要,我也许可以提供更多详细的帮助.

在您的架构中,我必须注释掉resourceURI行,然后将booleanInt更改为xs:Integer.

完成后,Altova能够使用该架构,这是它作为默认示例生成的:
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>



看起来您的XML应该显示为:



It would look like your XML should read:

<lineitems>
     <lineitem owned="0" quantity="1" productid="productID">1</lineitem>
</lineitems>




现在,另一方面,如果我们将您的XML固定下来,并要求Altova基于该XML片段生成模式,那么它将产生以下内容:




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>
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>


这篇关于XSD到XML的麻烦,传输与联合返回错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆