xmlxsdcomplextypesimpletype

Error: Must refer to an existing simple or complex type


I'm working in Altova and I'm creating an XSD file for my XML file and my code does not validate. I get the error:

Must refer to an existing simple or complex type

and I don't know why, because I've given a simpletype to the element name titel.

Does anyone know what I'm doing wrong?

P.S. Don't mind the values within the tags.

This is the XSD file:

   <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3schools.com CDS.xsd" xmlns:ns1="http://www.w3schools.com" targetNamespace="http://www.w3schools.com" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="catalogus" type="alles"/>
    <xs:complexType name="alles">
        <xs:sequence>
            <xs:element name="CD">
                <xs:complexType>
                    <xs:sequence>       

                        <!-- Elements -->
                        <xs:element name="titel" type="titelnaam"/>
                        <xs:element name="uitvoerder"/>
                        <xs:element name="uitgever"/>
                        <xs:element name="genre"/>
                        <xs:element name="prijs"/>
                        <xs:element name="jaar"/>
                        <xs:element name="behuizing"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>           
        </xs:sequence>
    </xs:complexType>

<!-- simpleTypes -->
<xs:simpleType name="titelnaam">
    <xs:restriction base="xs:string">
        <xs:pattern value="\d{3}-\d{1}-\d{3}-\d{5}-\d{1}"/>
    </xs:restriction>
</xs:simpleType>    
</xs:schema>

This is the XML file:

<?xml version="1.0"?>
<!DOCTYPE catalogus SYSTEM "CDS.dtd">
<catalogus>
<CD>
    <titel>Until Dawn</titel>
    <uitvoerder>Nirvana</uitvoerder>
    <uitgever>No Clue Music</uitgever>
    <genre>Jazz</genre>
    <prijs valuta="EU">19,95</prijs>
    <jaar>2002</jaar>
    <behuizing>double</behuizing>
    <tracks>
        <track>
            <nummer>Break away</nummer>
            <componist>Nirvana</componist>
            <tekstschrijver>Nirvana</tekstschrijver>
            <tijdsduur tijd="mm.ss">02.55</tijdsduur>
            <uitvoerder>Nirvana</uitvoerder>
        </track>
        <track>
            <nummer>Bananas</nummer>
            <componist>Nirvana</componist>
            <tekstschrijver>Nirvana</tekstschrijver>
            <tijdsduur tijd="mm.ss">03.55</tijdsduur>
            <uitvoerder>Nirvana</uitvoerder>
        </track>
    </tracks>
</CD>
</catalogus>

Solution

  • To eliminate this error,

    Must refer to an existing simple or complex type

    properly define a namespace prefix (ns1),

               xmlns:ns1="http://www.w3schools.com/CDS.xsd"
    

    covering the target namespace

               targetNamespace="http://www.w3schools.com/CDS.xsd"
    

    and use that to reference the type:

      <xs:element name="catalogus" type="ns1:alles"/>
    

    Altogether...

    XSD

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:ns1="http://www.w3schools.com/CDS.xsd"
               targetNamespace="http://www.w3schools.com/CDS.xsd"
               elementFormDefault="qualified"
               attributeFormDefault="unqualified">
      <xs:element name="catalogus" type="ns1:alles"/>
      <xs:complexType name="alles">
        <xs:sequence>
          <xs:element name="CD">
            <xs:complexType>
              <xs:sequence>       
    
                <!-- Elements -->
                <xs:element name="titel" type="ns1:titelnaam"/>
                <xs:element name="uitvoerder"/>
                <xs:element name="uitgever"/>
                <xs:element name="genre"/>
                <xs:element name="prijs"/>
                <xs:element name="jaar"/>
                <xs:element name="behuizing"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>           
        </xs:sequence>
      </xs:complexType>
    
      <!-- simpleTypes -->
      <xs:simpleType name="titelnaam">
        <xs:restriction base="xs:string">
          <xs:pattern value="\d{3}-\d{1}-\d{3}-\d{5}-\d{1}"/>
        </xs:restriction>
      </xs:simpleType>    
    </xs:schema>