Validating against schema: Employee.xsd
Error: Element 'Phone': The attribute 'Type' is not allowed. on line 9

Line
    1 <?xml version="1.0"?>
    2 <?xml-stylesheet href="http://courses.oreillyschool.com/introxml/xsl/PhoneBook.xsl" type="text/xsl"?>
    3 <!DOCTYPE Employees>
    4 <Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Employee.xsd">
    5  <Employee>
    6   <First>John</First>
    7   <Last>Smith</Last>
    8   <Phone Type="Home">1-800-123-4567</Phone>
    9   <Birthday>1960-05-25</Birthday>
   10   <HourlyRate>35.85</HourlyRate>
   11  </Employee>
   12 </Employees>
   13

Above is the error i get I have tried to fig this out for hours now i cant find a solution.

Here is my .xsd file. Thank you for your help.

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

  <xs:element name="Employees" type="EmployeesType"/>

  <xs:complexType name="EmployeesType">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="Employee" type="EmployeeType"/>
    </xs:sequence>
  </xs:complexType>

   <xs:complexType name="EmployeeType">
     <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="1" name="First" type="xs:token"/>
        <xs:element minOccurs="1" maxOccurs="1" name="Last" type="xs:token"/>
         <xs:element minOccurs="1" maxOccurs="1" name="Phone" type="xs:token"/>
        <xs:element minOccurs="0" maxOccurs="1" name="Birthday" type="xs:date"/>
        <xs:element minOccurs="0" maxOccurs="1" name="HourlyRate" type="xs:decimal"/>
     </xs:sequence>
  </xs:complexType>
  


</xs:schema>

I got it! You have to

<xs:element minOccurs="0" maxOccurs="1" name="Phone" type="PhoneType"/>

Then you can define the PhoneType complex type and the attribute.

<xs:complexType name="PhoneType">
    <xs:attribute name="Type" type="xs:token"/>
  </xs:complexType>

so the .xsd file looks like this

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

  <xs:element name="Employees" type="EmployeesType"/>

  <xs:complexType name="EmployeesType">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="Employee" type="EmployeeType"/>
    </xs:sequence>
  </xs:complexType>

   <xs:complexType name="EmployeeType">
     <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="1" name="First" type="xs:token"/>
        <xs:element minOccurs="1" maxOccurs="1" name="Last" type="xs:token"/>
         <xs:element minOccurs="0" maxOccurs="1" name="Phone" type="PhoneType"/>
        <xs:element minOccurs="0" maxOccurs="1" name="Birthday" type="xs:date"/>
        <xs:element minOccurs="0" maxOccurs="1" name="HourlyRate" type="xs:decimal"/>
     </xs:sequence>
  </xs:complexType>
  
  <xs:complexType name="PhoneType">
    <xs:attribute name="Type" type="xs:token"/>
  </xs:complexType>

</xs:schema>

The xml file I am validating

<?xml version="1.0"?>
<?xml-stylesheet href="http://courses.oreillyschool.com/introxml/xsl/PhoneBook.xsl" type="text/xsl"?>
<!DOCTYPE Employees>
<Employees
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Employee.xsd">
 <Employee>
  <First>John</First>
  <Last>Smith</Last>
  <Phone Type="Home">1-800-123-4567</Phone>
  <Birthday>1960-05-25</Birthday>
  <HourlyRate>35.85</HourlyRate>
 </Employee>
</Employees>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.