-1

This is my XML code-This part is well-formed and contain no errors while doing the validation.

<Employees>
<Employee>
 <Name>
    <FirstName>Tom</FirstName>
    <LastName>Sawyer</LastName>
 </Name>
 <Salary>10000</Salary>
 <Biography>
    Worked at the <Company>MCB Ltd</Company>
    as <JobTitle>Cashier</JobTitle>
 </Biography>
</Employee>

<Employee>
 <Name>
    <FirstName>John</FirstName>
    <LastName>Herold</LastName>
 </Name>
 <Wage>9500.25</Wage>
 <Biography>
    Worked at the <Company>University of Mauritius</Company>
    as <JobTitle>Software Engineer</JobTitle>
 </Biography>
</Employee>
</Employees>

This is my XSD code: The problem is here. I am getting this as error "element': The content is not valid. Expected is (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))."

I'm a beginner using xml and xsd. The question is as follows:

Use the following schema namespace:

  1. http://www.w3.org/2001/XMLSchema-instance
  2. Minimum & Maximum number of Employee:
  • Minimum : 1
  • Maximum: unbounded
  1. Salary is between 10,000 and 90,000 inclusive.
  2. Declare the types of the following elements as global types:
  • - write the name for this complexType as name

  • - write the name for this simpleType as salary

              <xs:element name="Employees">
              <xs:sequence> 
              <xs:element name="Employee" type="xs:String" minOccurs="1" maxOccurs="unbounded">
                  <xs:element name="Name" type="xs:String">
                  <xs:complexType name="name" type="xs:String">
                      <xs:element name="FirstName">
                          <xs:attribute name="Tom" type="xs:String"/>
                      </xs:element>
    
                      <xs:element name="LastName">
                          <xs:attribute name="Sawyer" type="xs:String"/>
                      </xs:element>
                  </xs:complexType>
                  </xs:element>
    
                  <xs:simpleType name="salary" type="xs:integer">
                      <xs:attribute name="10000" type="xs:integer" minInclusive="10000" maxInclusive="90000"/>
                  </xs:simpleType>
    
                  <xs:element name="Biography">
                      <xs:complexType mixed="true">
                          <xs:sequence>
                              <xs:element name="Company">
                                  <xs:attribute name="MCB Ltd" type="xs:String"/>
                              </xs:element>
    
                              <xs:element name="JobTitle">
                                  <xs:attribute name="Cashier" type="xs:String"/>
                              </xs:element>
                          </xs:sequence>
                      </xs:complexType>
                  </xs:element>
              </xs:element>
    
              <xs:element name="Employee" type="xs:String" minOccurs="1" maxOccurs="unbounded">
                  <xs:element name="Name" type="xs:String">
                  <xs:complexType name="name" type="xs:String">
                      <xs:element name="FirstName">
                          <xs:attribute name="John" type="xs:String"/>
                      </xs:element>
    
                      <xs:element name="LastName">
                          <xs:attribute name="Herold" type="xs:String"/>
                      </xs:element>
                  </xs:complexType>
                  </xs:element>
    
                  <xs:simpleType name="wage" type="integer">
                      <xs:attribute name="9500.25" type="xs:integer" />
                  </xs:simpleType>
    
                  <xs:element name="Biography">
                      <xs:complexType mixed="true">
                          <xs:sequence>
                              <xs:element name="Company">
                                  <xs:attribute name="University of Mauritius" type="xs:String"/>
                              </xs:element>
    
                              <xs:element name="JobTitle">
                                  <xs:attribute name="Software Engineer" type="xs:String"/>
                              </xs:element>
                          </xs:sequence>
                      </xs:complexType>
                  </xs:element>
              </xs:element>
    
          </xs:sequence>
          </xs:element>
          </xs:schema>
    
halfer
  • 19,824
  • 17
  • 99
  • 186
sheshna
  • 1
  • 1

2 Answers2

1

Lots of things wrong here, for example:

  • There's an xs:element declaration name="Name" that has both a type attribute and a contained xs:complexType declaration.

  • An xs:simpleType declaration with a name attribute (such as name="wage") can only appear as a child of xs:schema.

  • University of Mauritius is not a valid attribute name

  • 9500.25 is not a valid type name

This is all so wrong that one has to ask the meta-question: how are you approaching the task of learning this language? Because it looks to me as if you're read some examples and are trying to guess how the language works by reading the examples, and that ain't going to work. I found two things useful when I was learning XSD: (a) read a good book not the subject (e.g. the one by Priscilla Walmsley), (b) experiment with a tool (such as the one in Oxygen) that generates schemas from instance documents.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
0

You cannot directly nest a <xs:element/> element inside another <xs:element/>. It has to be part of a type specification using something like <xs:complexType/> containing <xs:sequence/>.

Christian Hujer
  • 17,035
  • 5
  • 40
  • 47