从导入中调用元素 XSD
Calling element from imported XSD
我的第一个xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="my.com/V1.0.xsd"
xmlns:abc="my.com/V1.0.xsd"
elementFormDefault="qualified">
我的新 xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="my.com/V2.0.xsd"
xmlns:abc="my.com/V2.0.xsd"
elementFormDefault="qualified">
<xs:import
namespace="my.com/V1.0.xsd" schemaLocation="V1.0.xsd"/>
我是 XSD 的新手,因此我的问题听起来可能很愚蠢,但如果有人能帮助我,那就太好了。
现在在 V2.0.xsd 中,我想在 V1.0.xsd 中调用元素,complexTypes,我该如何做这样的事情?我虽然现在所有元素都将聚集在 abc 命名空间下,但不幸的是,事情并没有像我希望的那样工作。
谢谢。
要在 v2 架构中导入 v1 元素,您必须在 v2 架构中限定对 v1 元素或 complexType 的引用。
例如:
给定这样的 v1 架构:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="my.com/V1.0.xsd"
xmlns:v1="my.com/V1.0.xsd"
elementFormDefault="qualified">
<xs:complexType name="typeV1">
<xs:sequence>
<xs:element name="fromV1"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
v2 模式这样调用复杂类型:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="my.com/V2.0.xsd"
xmlns:v2="my.com/V2.0.xsd"
xmlns:v1="my.com/V1.0.xsd"
elementFormDefault="qualified">
<xs:import namespace="my.com/V1.0.xsd" schemaLocation="v1.xsd"/>
<xs:element name="fromV2" type="v1:typeV1"/>
</xs:schema>
在结果 XML 中,必须声明两个名称空间,例如像那样:
<?xml version="1.0" encoding="UTF-8"?>
<v2:fromV2 xmlns:v2='my.com/V2.0.xsd'>
<v1:fromV1 xmlns:v1='my.com/V1.0.xsd'/>
</v2:fromV2>
如果您只需要一个命名空间,则必须在 targetNamespace 的两个架构中放置相同的 uri,并使用 include 而不是 import。
我的第一个xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="my.com/V1.0.xsd"
xmlns:abc="my.com/V1.0.xsd"
elementFormDefault="qualified">
我的新 xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="my.com/V2.0.xsd"
xmlns:abc="my.com/V2.0.xsd"
elementFormDefault="qualified">
<xs:import
namespace="my.com/V1.0.xsd" schemaLocation="V1.0.xsd"/>
我是 XSD 的新手,因此我的问题听起来可能很愚蠢,但如果有人能帮助我,那就太好了。
现在在 V2.0.xsd 中,我想在 V1.0.xsd 中调用元素,complexTypes,我该如何做这样的事情?我虽然现在所有元素都将聚集在 abc 命名空间下,但不幸的是,事情并没有像我希望的那样工作。
谢谢。
要在 v2 架构中导入 v1 元素,您必须在 v2 架构中限定对 v1 元素或 complexType 的引用。
例如: 给定这样的 v1 架构:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="my.com/V1.0.xsd"
xmlns:v1="my.com/V1.0.xsd"
elementFormDefault="qualified">
<xs:complexType name="typeV1">
<xs:sequence>
<xs:element name="fromV1"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
v2 模式这样调用复杂类型:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="my.com/V2.0.xsd"
xmlns:v2="my.com/V2.0.xsd"
xmlns:v1="my.com/V1.0.xsd"
elementFormDefault="qualified">
<xs:import namespace="my.com/V1.0.xsd" schemaLocation="v1.xsd"/>
<xs:element name="fromV2" type="v1:typeV1"/>
</xs:schema>
在结果 XML 中,必须声明两个名称空间,例如像那样:
<?xml version="1.0" encoding="UTF-8"?>
<v2:fromV2 xmlns:v2='my.com/V2.0.xsd'>
<v1:fromV1 xmlns:v1='my.com/V1.0.xsd'/>
</v2:fromV2>
如果您只需要一个命名空间,则必须在 targetNamespace 的两个架构中放置相同的 uri,并使用 include 而不是 import。