如何使 xsd 元素扩展另一个 [英] How to make xsd element extend another

查看:21
本文介绍了如何使 xsd 元素扩展另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个不同的 XML 元素,它们有一些共同的标签.

I have three different XML elements that have some common tags.

例如:人有姓名、年龄、性别

For e.g: Person has name, age, sex

然后我有经理、员工,它们将共享人员拥有的三个字段以及经理、员工特定字段,如 managerNo、employeeNo 等.

Then I have Manager, Employee that would share the three fields the Person has plus Manager, Employee specific fields like managerNo, employeeNo etc.

我可以在 xsd 中写一些像这样的东西吗:

Can I write something in xsd that would be like this:

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>

  1. 使用上面的 Person 声明并扩展 Manager 元素:

(只是我在寻找什么的想法)

实际上,我试图按照 Java(面向对象)继承来模拟我的模式定义,例如:

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
}

然后做:

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 继承概念,这样我就可以声明一个基本元素,并且只扩展该基本元素,以便其他子元素也继承基本元素的属性.

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.

推荐答案

简单使用:

<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>

这篇关于如何使 xsd 元素扩展另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆