XML服务订阅源验证会针对架构中断额外属性

时间:2013-01-29 17:26:16

标签: xml xsd

给定了支持旧的现有XML Feed的任务。新请求是向XML Feed添加新属性。当我将新属性“CountryOfOrigin”添加到XML然后添加到模式时,验证失败。现在,如果我从XML和模式中删除新属性,它就可以正常工作。这是带有新属性的新XML,下面是架构

XML

<TagOrder>
<Tag>
<Message>1</Message>
<TagType>R</TagType>
<ItemNumber>190</ItemNumber>
<ItemXRef>E039</ItemXRef>
<VendorXRef>E39H</VendorXRef>
<Lvl02Desc>NEAR</Lvl02Desc>
<Lvl03Desc>NUG</Lvl03Desc>
<Lvl04Desc>EARRING</Lvl04Desc>
<Lvl05Desc>14KT</Lvl05Desc>
<Lvl06Desc></Lvl06Desc>
<VendorShortName>TEST</VendorShortName>
<SRP>1325.00</SRP>
<RetailPrice>1325.00</RetailPrice>
<CountryOfOrigin>TEST</CountryOfOrigin>
</Tag>
</TagOrder>

模式

<schema id="Data2-Tag" xmlns="http://www.w3.org/2001/XMLSchema">`
<element name="Transaction">
    <complexType>
        <sequence>

            <element name="TransactionId" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="long">
                    </restriction>
                </simpleType>
            </element>

            <element name="ClientId" minOccurs="1" maxOccurs="1">
                <simpleType>
                    <restriction base="long">
                    </restriction>
                </simpleType>
            </element>

            <element name="TagOrder" minOccurs="1" maxOccurs="unbounded">
                <complexType>
                    <sequence>

                        <element name="Tag" minOccurs="1" maxOccurs="unbounded">
                            <complexType>
                                <sequence>

                                    <element name="Message" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="int">
                                                <minExclusive value="0"/>
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="TagType" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="1"/>
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="ItemNumber" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="50"/>
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="ItemXRef" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="20" />
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="VendorXRef" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="20" />
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="Lvl02Desc" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="4" /> 
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="Lvl03Desc" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="3" />
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="Lvl04Desc" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="9" />
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="Lvl05Desc" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="8" />
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="Lvl06Desc" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="3" />
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="Lab" minOccurs="0" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="20"></maxLength>
                                                <enumeration value="Cultured"/>
                                                <enumeration value="Lab Created"/>
                                            </restriction>
                                        </simpleType>
                                    </element>


                                    <element name="VendorShortName" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="3"/>
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="SRP" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="decimal">
                                                <minInclusive value="0" />
                                                <fractionDigits value="2"/>
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="RetailPrice" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="decimal">
                                                <minInclusive value="0" />
                                                <fractionDigits value="2"/>
                                            </restriction>
                                        </simpleType>
                                    </element>

                                    <element name="CountryOfOrigin" minOccurs="1" maxOccurs="1">
                                        <simpleType>
                                            <restriction base="string">
                                                <maxLength value="100"/>
                                            </restriction>
                                        </simpleType>
                                    </element>

                                </sequence>
                            </complexType>
                        </element>

                    </sequence>
                </complexType>
            </element>

        </sequence>
    </complexType>
</element>

如果我从两者中删除“CountryOfOrigin”,它可以正常工作并验证。任何人都明白为什么XML不会针对架构进行验证?

感谢 ^。^

1 个答案:

答案 0 :(得分:0)

我能够验证以下XML:

<?xml version="1.0" encoding="UTF-8"?>
<Transaction>
    <TransactionId>123456789123</TransactionId>
    <ClientId>987654321</ClientId>
    <TagOrder>
        <Tag>
            <Message>1</Message>
            <TagType>R</TagType>
            <ItemNumber>190</ItemNumber>
            <ItemXRef>E039</ItemXRef>
            <VendorXRef>E39H</VendorXRef>
            <Lvl02Desc>NEAR</Lvl02Desc>
            <Lvl03Desc>NUG</Lvl03Desc>
            <Lvl04Desc>EARRING</Lvl04Desc>
            <Lvl05Desc>14KT</Lvl05Desc>
            <Lvl06Desc></Lvl06Desc>
            <VendorShortName>TES</VendorShortName>
            <SRP>1325.00</SRP>
            <RetailPrice>1325.00</RetailPrice>
            <CountryOfOrigin>TEST</CountryOfOrigin>
        </Tag>
    </TagOrder>
</Transaction>