首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >验证XSD失败-未声明属性

验证XSD失败-未声明属性
EN

Stack Overflow用户
提问于 2021-09-14 20:55:20
回答 1查看 146关注 0票数 0

我有以下我已经裁剪的xml,但它所做的就是为它的每个sku,它按照前6位数字将它们分组,形成一个产品,该产品出现在文件的末尾,具有更多的元素,例如,下面是3个sku和1个产品:

代码语言:javascript
复制
<?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,它生成了两个文件,第一个是:

代码语言:javascript
复制
<?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>

第二个是:

代码语言:javascript
复制
<?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

单击ok后,我尝试验证模式,但只收到this error。我确实注意到xml文件引用了一个名为catalog.xsd的模式,但没有使用,因此假设它不是必需的,以及另一个使用的名为dt.xsd的模式(dt:dt),这是我从客户端获得的:

代码语言:javascript
复制
<?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中的create xsd仍然不能工作:

代码语言:javascript
复制
<?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> 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-15 07:41:30

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69184426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档