微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xml – 如何使xsd元素扩展另一个

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

例如:人有姓名,年龄,性别
然后我有经理,员工,将分享人员有三个字段加上经理,员工特定字段,如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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。