I have three different XML elements that have some common tags.
For e.g: Person has name, age, sex
Then I have Manager, Employee that would share the three fields the Person has plus Manager, Employee specific fields like managerNo, employeeNo etc.
Can I write something in xsd that would be like this:
1. Declare Person element
<xsd:element name="Person">
<xsd:annotation>
<xsd:documentation>Person Request</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="personname" type="xsd:string" minOccurs="1" maxOccurs="1" />
<xsd:element name="age" type="xsd:integer" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Manager" extends="tns:Person"> (just idea of what I am looking for)
In effect, I am trying to mimic my schema definition as per Java (object oriented) inheritance like:
public class Person {
String name;
int age;
// getters and setters for above variables go here
}
then do:
public class Manager extends Person {
int managerNo;
String departmentName;
}
public class Employee extends Person {
int employeeNo;
String designation;
// getters/setters and other code goes here
}
I want to mimic this Java inheritance concept in the xsd such that I can declare one base element, and just extend that base element such that other child elements also inherit the properties of base element.
Simply use:
<xs:extension base="AddressType">
in your Manager/Employye schema definition
<xs:complexType name="Manager">
<xs:complexContent>
<xs:extension base="Person">
<xs:sequence>
<!-- Properties -->
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With