0

In a xsd, I include and import some element. Imported one is not resolved, I get this error:

Error: src-resolve: Cannot resolve the name 'crq1:CoverageRequest' to a(n) 'type definition' component.

OfferRequest.xsd

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.example.org/Test4"
        xmlns:crq1="http://www.example.org/CoverageRequestOffer"
        xmlns:tns="http://www.example.org/Test4">

        <xsd:import namespace="http://www.example.org/CoverageRequestOffer"
            schemaLocation="CoverageRequestOffer.xsd" />

        <xsd:include schemaLocation="OfferScope.xsd"/>
        <xsd:include schemaLocation="OfferConstraints.xsd"/>
        <xsd:include schemaLocation="PricingConstraints.xsd"/>

        <xsd:element name="OfferRequest">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="Configuration" type="tns:OfferScope" />
                    <xsd:element name="Coverage" type="crq1:CoverageRequest" />  <!-- ***** error ***** -->
                    <xsd:element name="ResponseConstraints" type="tns:OfferConstraints"/>
                    <xsd:element name="RequestConstraints" type="tns:PricingConstraints"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>

CoverageRequestOffer.xsd

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:tns="http://www.example.org/Test4"
        targetNamespace="http://www.example.org/CoverageRequestOffer"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">

        <xsd:import namespace="http://www.example.org/Test4"
            schemaLocation="TypeOfVehicule.xsd" />

        <xsd:import namespace="http://www.example.org/Test4"
            schemaLocation="Insured.xsd" />

        <xsd:import namespace="http://www.example.org/Test4"
            schemaLocation="TypeOfCoverageCategory.xsd" />

        <xsd:element name="CoverageRequest">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="PurchaseDate" type="xsd:dateTime" />
                    <xsd:element name="StartDate" type="xsd:dateTime" />
                    <xsd:element name="EndDate" type="xsd:dateTime" />
                    <xsd:element name="VehicleCategory" type="tns:TypeOfVehicule" />
                    <xsd:element name="TravelDestination" type="xsd:string"
                        minOccurs="0" maxOccurs="255" />
                    <xsd:element name="DiscountCodes" type="xsd:string"
                        maxOccurs="unbounded" minOccurs="0" />
                    <xsd:element name="DeductibleCode" type="xsd:string"
                        minOccurs="0" maxOccurs="25" />
                    <xsd:element name="ProvinceOfResidence" type="xsd:string"
                        minOccurs="1" maxOccurs="255" />
                    <xsd:element name="Insured" type="tns:Insured"
                        minOccurs="1" />
                    <xsd:element name="CoverageCategory" type="tns:TypeOfCoverageCategory" />
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>

In namespace: http://www.example.org/Test4, CoverageRequest type exist.

Any info to resolve this error?

user1761239
  • 33
  • 1
  • 4

2 Answers2

1

You are referring to a type with the name "crq1:CoverageRequest" but there is only an element with that name.

In other words, the resolver is looking for something like

<xsd:complexType name="CoverageRequest">

but you have

<xsd:element name="CoverageRequest">
Erik Sjölund
  • 10,690
  • 7
  • 46
  • 74
1

Erik Sjölund has already pointed out the immediate cause of your problem.

There are two possible fixes:

  • Add a declaration for a complex type named CoverageRequest to the schema document for the namespace http://www.example.org/CoverageRequestOffer (if you control that schema document).

    Or (assuming that the type you want is the type of the CoverageRequest element) move the complex type out of the CoverageRequest element declaration, so the relevant part of the schema reads:

    <xsd:element name="CoverageRequest" 
                 type="tns:CoverageRequest"
                 xmlns:tns="http://www.example.org/CoverageRequestOffer">
    
    <xsd:complexType name="CoverageRequest">
      <xsd:sequence>
        <xsd:element name="PurchaseDate" type="xsd:dateTime" />
        <xsd:element name="StartDate" type="xsd:dateTime" />
        ...
      </
    </
    
  • Change the schema for namespace http://www.example.org/Test4 to refer not to the type but to the element.

    Specifically, in the declaration of element OfferRequest, change

    <xsd:element name="Coverage" type="crq1:CoverageRequest" />
    

    to

    <xsd:element ref="crq1:CoverageRequest" />
    

    This is not exactly the same, because your XML will now need to have an element named crq1:CoverageRequest (or the equivalent) as the second child of OfferRequest, instead of an element named test4:Coverage (or the equivalent). But if you don't control the schema document for namespace http://www.example.org/CoverageRequestOffer, it may be the best thing to do.

C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65