Home > Software engineering >  xsd validation failed - Reference local xsd file
xsd validation failed - Reference local xsd file

Time:09-21

I have an xml file that has dt:dt which I've never seen before:

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

When I used VS to create an xsd based on the above xml, it created 2 files:

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

and

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

I believe I need to edit the larger of the xsd so it knows where the other xsd schema is, but how do I do that? Currently when I open the larger xsd back in VS it just has this error

I tried changing

<xs:import namespace="intershop.com/xml/ns/enfinity/6.5/core/impex-dt" />

to

<xs:import namespace="intershop.com/xml/ns/enfinity/6.5/core/impex-dt" dt:schemaLocation="C:\Users\TommyTam\Downloads\Upload To Exponea\Mulesoft\Item Variant Flow Poll\Item Variant Flow Poll_XML (ADDITIONAL).xsd dt.xsd"/>

but it's still not correct.

CodePudding user response:

The xs:import element takes as the schemaLocation attribute (https://www.w3.org/TR/xmlschema-0/#schemaLocation) a relative or absolute URL to a file containing the schema for that namespace so e.g. <xs:import namespace="http://www.intershop.com/xml/ns/enfinity/6.5/core/impex-dt" schemaLocation="dt.xsd"/> would be a way to point to the local file named dt.xsd in the same directory as the file containing the xs:import declaration.

  • Related