2

给定一项支持旧的现有 XML 提要的任务。新请求正在向 XML 提要添加新属性。当我将新属性“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 不会针对模式进行验证?

谢谢^.^

4

1 回答 1

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>
于 2013-01-29T19:36:35.033 回答