【发布时间】:2016-09-19 15:09:50
【问题描述】:
此代码是组合在一起的大量 xsd 文件的一部分..
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Headers"
targetNamespace="http://HttpNamespace/types"
elementFormDefault="qualified"
xmlns="http://HttpNamespace/types"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:saml ="http://HttpNamespace/saml"
>
<xs:import namespace="http://HttpNamespace/saml" schemaLocation="Saml.xsd" />
<xs:complexType name="ConnectionHeader">
<xs:attribute name="key" fixed="Connection" />
<xs:attribute name="value" >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="keep-alive" />
<xs:enumeration value="close" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:complexType name="ContentTypeHeader">
<xs:attribute name="key" fixed="Content-Type" />
<xs:attribute name="value" >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="application/json" />
<xs:enumeration value="application/soap+xml" />
<xs:enumeration value="text/xml" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:complexType name="AuthorizationHeader">
<xs:sequence>
<xs:element name="Saml" minOccurs="0" maxOccurs="1" type="saml:SamlContent"/>
</xs:sequence>
<xs:attribute name="key" fixed="Authorization"/>
</xs:complexType>
<xs:complexType name="HeadersType">
<xs:sequence>
<xs:element name="Header" maxOccurs="unbounded">
<xs:complexType>
<xs:choice>
<xs:element name="Header" minOccurs="0" maxOccurs="1" type="ConnectionHeader" />
<xs:element name="Header" minOccurs="0" maxOccurs="1" type="ContentTypeHeader" />
<xs:element name="Header" minOccurs="0" maxOccurs="1" type="AuthorizationHeader" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
正如你所看到的,在复杂类型 HeadersType 中,我试图在 3 种具有相同元素名称“Header”的复杂类型之间进行选择。所有 3 种类型都在这段代码 sn-p 中定义。
但是编辑一直给我抛出错误:
元素 Header 的多个定义导致内容模型 变得模棱两可
所以我的问题是我如何定义具有不同复杂类型的同一元素的多项选择?
【问题讨论】: