0
votes

I am looking to have an element reference a sibling but I am unsure how to implement this in my schema. I have the following in my .xml file:

 <staff pid="818789">
     <supervisor staff="201022"></supervisor>
     ...
 </staff>

Meaning each member of staff will have a supervisor who is also a member of staff so I am looking to reference them if this is possible.

"pid" is a type I have created in my schema which is just a string of 6 digits.

I have the following in my .xsd file:

 <xs:element name="staff">
    <xs:complexType>    
        <xs:sequence>
            <xs:element name="supervisorID" type="pidType" minOccurs="0" maxOccurs="1"/>
            ...
        </xs:sequence>
        <xs:attribute name="pid" type="pidType" use="required"/>
    </xs:complexType>
 </xs:element>

It gives the following error:

ERROR - cvc-type.3.1.1: Element 'supervisor' is a simple type, so it cannot have attributes, excepting those whose namespace name is identical to 'http://www.w3.org/2001/XMLSchema-instance' and whose [local name] is one of 'type', 'nil', 'schemaLocation' or 'noNamespaceSchemaLocation'. However, the attribute, 'staff' was found.

Which I can see why it raises the error but don't understand what I would change it to.

1
show us the complete xsd for staff elementKachna
It's completely unrelated so why would it matter?Porteous96

1 Answers

1
votes

the element that has attributes must be complex type. So the supervisor element should be defined as follow

<xs:element name="supervisor">
        <xs:complexType>

                  <xs:attribute  name="staff" type = "pidType" use="required"/>

        </xs:complexType>

</xs:element>