1
votes

M stuck with this error please help me out.....

My .xml file is

<?xml version="1.0"?>
<addresses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:noNamespaceSchemaLocation='Lsc.xsd'>
<lscApplicationform>
 <programmes>
  <course>MBA(12 months)</course>
 </programmes>
 <personalDetails>
 <surname>Sagar</surname>
 <firstname>Shiva</firstname>
 <gender>Male</gender>
 <placeofbirth>Ulhasnagar</placeofbirth>
 <nationality>Indian</nationality>
 <countryofbirth>India</countryofbirth>
 <dateofbirth>1993-06-03</dateofbirth>
</personalDetails>
<permanentAddress>
</permanentAddress>
</lscApplicationform>
</addresses>

and my xsd file is

<?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xs:element name="lscApplicationForm">
      <xs:complexType>
       <xs:sequence>
        <xs:element name="programmeType" type="xs:string">
               <xs:simpleType>
         <xs:restriction base="xs:string">
          <xs:enumeration value="MBA( months)"/>
          <xs:enumeration value="MBA( months)"/>
          <xs:enumeration value="MSc InformationTechnology"/>
          <xs:enumeration value="Msc InternationalHospitalityManagement"/>
          <xs:enumeration value="Msc InternationalTourismManagement"/>
          <xs:enumeration value="BA(Hons)BusinessStudies"/>
          <xs:enumeration value="BSc(Hons)Computing"/>
          <xs:enumeration value="PhD/ProfessionaDoctorate"/>
          <xs:enumeration value="Other(pleasespecify)"/>
         </xs:restriction>
           </xs:simpleType>




                <xs:element name="personalDetails" type="xs:string"/>
        <xs:complexType>
         <xs:sequence>
          <xs:element name="Surname" type="xs:string"/>
           <xs:simpleType>
            <xs:restriction base="xs:string">
             <xs:length value="100"/>
            </xs:restriction>
           </xs:simpleType>


          <xs:element name="Gender"/>
           <xs:simpleType>
            <xs:restriction base="xs:string">
             <xs:pattern value="male|female"/>
            </xs:restriction>
           </xs:simpleType>


          <xs:element name="placeOfBirth" type="xs:string"/>
          <xs:element name="Nationality" type="xs:string"/>
          <xs:element name="CountryOfBirth" type="xs:string"/>
          <xs:element name="dob" type="xs:date"/>
         </xs:sequence>    
        </xs:complexType>
        <xs:element name="permanentAddress" type="xs:string"/>
               <xs:complexType> 
               </xs:complexType> 
</xs:element>              
</xs:sequence>
</xs:complexType>      
</xs:element>
    </xs:schema>

and one more error is s4s-elt-must-match.1: The content of 'programmeType' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: element.

Thanks in advance....

2

2 Answers

4
votes

The XML syntax of XSD schema documents is complicated enough that it really pays to use an editor that understands XSD syntax and can validate as you go. With or without such an editor, you probably want to spend some time reviewing a basic tutorial on XSD.

Your basic problem, which appears several times in different forms, is that your schema document does not obey the syntactic constraints for schema documents.

  • Several of your element declarations have type="xs:string", which specifies that the type of the element is xs:string, and also have xs:simpleType or xs:complexType children, which specifies that the type of the element is something different. On any element declaration use either the type attribute or a type definition child (simpleType or complexType), not both.

  • Several of your element declarations are tagged as empty elements immediately followed by a simpleType or complexType element which I guess is intended to be a child of the element declaration, not a following sibling.

Once you fix these problems, your schema document will be syntactically OK, and you can then turn your attention to making it say what you want it to say.

1
votes

Try this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="addresses">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="lscApplicationform"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="lscApplicationform">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="programmes">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="course">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:enumeration value="MBA( months)"/>
                    <xs:enumeration value="MBA( months)"/>
                    <xs:enumeration value="MSc InformationTechnology"/>
                    <xs:enumeration value="Msc InternationalHospitalityManagement"/>
                    <xs:enumeration value="Msc InternationalTourismManagement"/>
                    <xs:enumeration value="BA(Hons)BusinessStudies"/>
                    <xs:enumeration value="BSc(Hons)Computing"/>
                    <xs:enumeration value="PhD/ProfessionaDoctorate"/>
                    <xs:enumeration value="Other(pleasespecify)"/>
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="personalDetails">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Surname">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:length value="100"/>
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>


              <xs:element name="Gender">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:pattern value="male|female"/>
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>

              <xs:element name="placeOfBirth" type="xs:string"/>
              <xs:element name="Nationality" type="xs:string"/>
              <xs:element name="CountryOfBirth" type="xs:string"/>
              <xs:element name="dob" type="xs:date"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

        <xs:element name="permanentAddress" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>