0

I have two schemas. The first schema defines the type BasicSequence (file Basic.xsd).

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns="http://basic-schema.com" 
    targetNamespace="http://basic-schema.com" 
    elementFormDefault="qualified" 
    attributeFormDefault="unqualified">

    <xs:complexType name="BasicSequence">
        <xs:sequence>
            <xs:element name="ElementA" type="xs:string"/>
            <xs:any />
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="MySequence1">
        <xs:complexContent>
            <xs:restriction base="BasicSequence">
                <xs:sequence>
                    <xs:element name="ElementA" type="xs:string"/>
                    <xs:element name="ElementB" type="xs:string"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>    

</xs:schema>

In the second schema I'm trying to define a type based on BasicSequence:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:basic="http://basic-schema.com" 
    elementFormDefault="qualified" 
    attributeFormDefault="unqualified">
    <xs:import namespace="http://basic-schema.com" schemaLocation="Basic.xsd"/>
    <xs:complexType name="MySequence2">
        <xs:complexContent>
            <xs:restriction base="basic:BasicSequence">
                <xs:sequence>
                    <xs:element name="ElementA" type="xs:string"/>
                    <xs:element name="ElementB" type="xs:string"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
</xs:schema>

But during parsing I get the next error:

Invalid particle derivation by restriction - 'Derived element 'ElementA' is not a valid restriction of base element 'http://basic-schema.com:ElementA' according to Elt:Elt -- NameAndTypeOK.'

As you can see, MySequence1 and MySequence2 have the same structure. But MySequence1 is successfully parsed and MySequence2 is not.

Please, help to understand what is wrong.

Igorious
  • 81
  • 5

1 Answers1

0

It seems strange to me that you're trying to use xs:import instead of xs:include.

See What's the difference between xsd:include and xsd:import? for the detailed information.

  • OK, I've replaced `import` by ``. After that, a schema parser requires `targetNamespace`. I've also added it, and now the schema is valid. But I don't understand, why I need to define `targetNamespace`. – Igorious Nov 19 '18 at 16:30