加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 22:54:49 所属栏目:百科 来源:网络整理
导读:我有三个不同的 XML元素,它们有一些共同的标签. 例如:人有姓名,年龄,性别 然后我有经理,员工,将分享人员有三个字段加上经理,员工特定字段,如managerNo,employeeNo等. 我可以在xsd中写一些像这样的东西 1.声明Person元素 xsd:element name="Person" xsd:anno
我有三个不同的 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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读