验证 XSD 失败 - 属性未声明

Validate XSD Failed - The attribute is not declared

我有以下 xml 我已经削减了,但它所做的只是针对它拥有的每个 sku,它按前 6 位数字将它们分组以形成一个产品,该产品出现在最后包含更多元素的文件,例如以下是 3 个 SKU 和 1 个产品:

<?xml version='1.0' encoding='UTF-8'?>
<enfinity xsi:schemaLocation="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex catalog.xsd http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt dt.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:dt="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt" major="6" minor="1" family="enfinity" branch="enterprise" build="build">
  <offer sku="423182110">
    <short-description xml:lang="de-DE">Budlea Linen Skirt</short-description>
    <custom-attributes>
      <custom-attribute name="sizeEU" dt:dt="string">42</custom-attribute>
    </custom-attributes>
  </offer>
  <offer sku="423182111">
    <short-description xml:lang="de-DE">Budlea Linen Skirt</short-description>
    <custom-attributes>
      <custom-attribute name="sizeEU" dt:dt="string">44</custom-attribute>
    </custom-attributes>
  </offer>
  <offer sku="423182112">
    <short-description xml:lang="de-DE">Budlea Linen Skirt</short-description>
    <custom-attributes>
      <custom-attribute name="sizeEU" dt:dt="string">46</custom-attribute>
    </custom-attributes>
  </offer>
  <offer sku="423182">
    <short-description xml:lang="de-DE">Budlea Linen Skirt</short-description>
    <variations>
      <mastered-products>
        <mastered-product sku="423182110" domain="WhiteStuff-MasterRepository" default="1" productvariationposition="500"/>
        <mastered-product sku="423182111" domain="WhiteStuff-MasterRepository" default="0" productvariationposition="600"/>
        <mastered-product sku="423182112" domain="WhiteStuff-MasterRepository" default="0" productvariationposition="700"/>
      </mastered-products>
      <variation-attributes>
        <variation-attribute name="size">
          <presentation-option>default</presentation-option>
          <custom-attributes>
            <custom-attribute name="displayName" dt:dt="string" xml:lang="en-US">Size</custom-attribute>
          </custom-attributes>
        </variation-attribute>
        <variation-attribute name="colour">
          <presentation-option>colorCode</presentation-option>
          <presentation-product-attribute-name>rgbColour</presentation-product-attribute-name>
          <custom-attributes>
            <custom-attribute name="displayName" dt:dt="string" xml:lang="en-US">Colour</custom-attribute>
          </custom-attributes>
        </variation-attribute>
      </variation-attributes>
    </variations>
    <custom-attributes>
      <custom-attribute name="sizeBridge" dt:dt="string">WW STD</custom-attribute>
      <custom-attribute name="washCareProfile" dt:dt="string">Machine Washable</custom-attribute>
    </custom-attributes>
  </offer>
</enfinity> 

我使用 Visual Studio 生成了 xsd,生成了 2 个文件,第一个是:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:attribute name="dt" type="xs:string" />
</xs:schema>

第二个是:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dt="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:import namespace="http://www.w3.org/XML/1998/namespace" />
    <xs:import namespace="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt" />
    <xs:element name="enfinity">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" name="offer">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="short-description">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute ref="xml:lang" use="required" />
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                            <xs:element minOccurs="0" name="variations">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="mastered-products">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element maxOccurs="unbounded" name="mastered-product">
                                                        <xs:complexType>
                                                            <xs:attribute name="sku" type="xs:unsignedInt" use="required" />
                                                            <xs:attribute name="domain" type="xs:string" use="required" />
                                                            <xs:attribute name="default" type="xs:unsignedByte" use="required" />
                                                            <xs:attribute name="productvariationposition" type="xs:unsignedShort" use="required" />
                                                        </xs:complexType>
                                                    </xs:element>
                                                </xs:sequence>
                                            </xs:complexType>
                                        </xs:element>
                                        <xs:element name="variation-attributes">
                                            <xs:complexType>
                                                <xs:sequence>
                                                    <xs:element maxOccurs="unbounded" name="variation-attribute">
                                                        <xs:complexType>
                                                            <xs:sequence>
                                                                <xs:element name="presentation-option" type="xs:string" />
                                                                <xs:element minOccurs="0" name="presentation-product-attribute-name" type="xs:string" />
                                                                <xs:element name="custom-attributes">
                                                                    <xs:complexType>
                                                                        <xs:sequence>
                                                                            <xs:element name="custom-attribute">
                                                                                <xs:complexType>
                                                                                    <xs:simpleContent>
                                                                                        <xs:extension base="xs:string">
                                                                                            <xs:attribute name="name" type="xs:string" use="required" />
                                                                                            <xs:attribute ref="dt:dt" use="required" />
                                                                                            <xs:attribute ref="xml:lang" use="required" />
                                                                                        </xs:extension>
                                                                                    </xs:simpleContent>
                                                                                </xs:complexType>
                                                                            </xs:element>
                                                                        </xs:sequence>
                                                                    </xs:complexType>
                                                                </xs:element>
                                                            </xs:sequence>
                                                            <xs:attribute name="name" type="xs:string" use="required" />
                                                        </xs:complexType>
                                                    </xs:element>
                                                </xs:sequence>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="custom-attributes">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" name="custom-attribute">
                                            <xs:complexType>
                                                <xs:simpleContent>
                                                    <xs:extension base="xs:string">
                                                        <xs:attribute name="name" type="xs:string" use="required" />
                                                        <xs:attribute ref="dt:dt" use="required" />
                                                    </xs:extension>
                                                </xs:simpleContent>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="sku" type="xs:unsignedInt" use="required" />
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute name="major" type="xs:unsignedByte" use="required" />
            <xs:attribute name="minor" type="xs:unsignedByte" use="required" />
            <xs:attribute name="family" type="xs:string" use="required" />
            <xs:attribute name="branch" type="xs:string" use="required" />
            <xs:attribute name="build" type="xs:string" use="required" />
        </xs:complexType>
    </xs:element>
</xs:schema>

第一个文件很好,虽然它没有很多信息,所以不太确定它的用途。尽管如此,当我保存第二个文件并尝试在 Visual Studio 中打开它时,我得到 this error:

单击“确定”后,我尝试验证架构,但也只收到 this error。我确实注意到 xml 文件引用了一个名为 catalog.xsd 的模式但未被使用,因此假设它不是必需的,以及另一个名为 dt.xsd 的模式被使用(dt:dt ), 这是我从客户那里得到的:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
    targetNamespace="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:attribute name="dt">
        <xsd:simpleType>
            <xsd:restriction base="xsd:string">
                <xsd:enumeration value="int" />
                <xsd:enumeration value="double" />
                <xsd:enumeration value="string" />
                <xsd:enumeration value="long" />
                <xsd:enumeration value="boolean" />
                <xsd:enumeration value="date" />
                <xsd:enumeration value="decimal" />
                <xsd:enumeration value="money" />
                <xsd:enumeration value="quantity" />
                <xsd:enumeration value="text" />
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:attribute>
</xsd:schema>

我的最终目标是在 VS 中打开此文件而不会出现任何错误,并开始创建映射文件,以便我可以使用 BizTalk 将 CSV 转换为 XML。但是现在我什至无法创建一个简单的 xsd 文件,这真的很令人沮丧,我对这一切都是新手所以请原谅我的无知。

看起来即使我的 xml 变得更小,如下所示,VS 中的创建 xsd 仍然不起作用:

<?xml version='1.0' encoding='UTF-8'?>
<enfinity xsi:schemaLocation="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex catalog.xsd http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt dt.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.intershop.com/xml/ns/enfinity/7.0/xcs/impex" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:dt="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt" major="6" minor="1" family="enfinity" branch="enterprise" build="build">
  <offer sku="423182110">
    <custom-attributes>
      <custom-attribute name="sizeEU" dt:dt="string">42</custom-attribute>
    </custom-attributes>
  </offer>
</enfinity> 

它正确地生成了两个模式文档,一个用于您的源 XML 中使用的两个名称空间中的每一个,并且它正确地生成了一个 xs:import 从另一个引用其中一个。但是在xs:import中,它实际上并没有生成schemaLocation属性,大概是因为它不知道你要把这两个schema文档放在哪里。您需要手动添加 schemaLocation

请注意,我不同意@kimbert,我认为使用模式生成器是为您的数据生成初始模式的完美方式。但它永远不会完美:您将始终需要手动修改它以反映您对数据语义的了解。例如,它已选择 xs:unsignedInt 作为 SKU 的数据类型,但如果前导零很重要并且需要保留,则该选择将是错误的。