xml - 从其他 XML 模式继承:重新定义单个类型而不触及基础 xsd
问题描述
我有一个想要扩展的在线 XML 模式。它看起来像这样:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:inheritance:1"
xmlns="urn:inheritance:1"
>
<xs:complexType name="aType">
<xs:sequence>
<xs:element name="b" type="bType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="bType">
<xs:sequence>
<xs:element name="c"/>
</xs:sequence>
</xs:complexType>
<xs:element name="a" type="aType"/>
</xs:schema>
其中我想扩展类型bType
我目前的解决方案是:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:inheritance:2"
xmlns="urn:inheritance:2"
xmlns:inh="urn:inheritance:1"
>
<xs:redefine schemaLocation="urn:inheritance:1">
<xs:complexType name="aType">
<xs:complexContent>
<xs:extension base="aType">
<xs:sequence>
<xs:element name="b" type="bType"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="bType">
<xs:complexContent>
<xs:extension base="bType">
<xs:sequence>
<xs:element name="newC" type="newCType"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
<xs:element name="a" type="aType"/>
<xs:complexType name="newCType"/>
</xs:schema>
我发现这非常麻烦并且实际上并没有完全解决我的问题,因为如果bType
完全在其他地方使用,我必须重复这个结构。
是否可以做这样的事情,我只是重新定义类型,以便我的原始方案用这个更新的类型更新:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:inheritance:2"
xmlns="urn:inheritance:2"
xmlns:inh="urn:inheritance:1"
>
<xs:redefine schemaLocation="urn:inheritance:1">
<xs:complexType name="bType">
<xs:complexContent>
<xs:extension base="bType">
<xs:sequence>
<xs:element name="newC" type="newCType"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
<xs:element name="a" type="aType"/>
<xs:complexType name="newCType"/>
</xs:schema>
解决方案
推荐阅读
- html - 如何在我的链接标签下获得我的链接?
- terraform - 如何使用 CODE_DEPLOY 部署控制器更新现有 ECS 服务的 desired_count?
- python - “:”在python的格式方法中做了什么?
- xml - 使用属性中的对齐信息通过 xslt 对齐 xml 元素
- excel - 使用 VBA 从表中生成列表框项
- r - 如何编写一个系数在 R 中趋于 0 的函数?
- actionscript-3 - 将十进制数转换为分数 AS3
- algorithm - 算法的运行时间
- java - 为键存储多个值?
- reactjs - SemanticUI Form.Input 类型的电子邮件和电话添加了 aria-invalid 属性