我有三个不同的 XML元素,它们有一些共同的标签. 例如:人有姓名,年龄,性别 然后我有经理,员工,将分享人员有三个字段加上经理,员工特定字段,如managerNo,employeeNo等. 我可以在xsd中写一些
例如:人有姓名,年龄,性别
然后我有经理,员工,将分享人员有三个字段加上经理,员工特定字段,如managerNo,employeeNo等.
我可以在xsd中写一些像这样的东西
1.声明Person元素
<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>
>使用上面的Person声明并扩展Manager元素:
(只想到我要找的东西)
实际上,我试图模仿我的模式定义按照Java(面向对象)继承,如:
public class Person {
String name;
int age;
// getters and setters for above variables go here
}
然后做:
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
}
我想在xsd中模仿这个Java继承概念,这样我就可以声明一个基本元素,并只扩展该基本元素,使其他子元素也继承基本元素的属性.
提前致谢.
只需使用:<xs:extension base="AddressType">
在Manager / Employye架构定义中
<xs:complexType name="Manager">
<xs:complexContent>
<xs:extension base="Person">
<xs:sequence>
<!-- Properties -->
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
