我有两个具有相同名称但属性不同的子元素。有没有办法为它编写有效的XSD。
我现在得到的错误是:模型组中出现了具有名称链接和不同类型的多个元素
我有这样的XML:
<entry>
<id> 123 </id>
<link rel="alternate" type="text/html" href="ABC.html" />
<link rel="amphtml" href="https:ABCD.html" >
<inline:inline type="text/html">
<![CDATA[
<!doctype html>
<html amp>
</html>
]]>
</inline:inline>
</link>
</entry>
我正在定义XSD:
<xs:element name="entry" type="atom:entryType"/>
<xs:complexType name="entryType">
<xs:annotation>
<xs:documentation>
The Atom entry construct is defined in accordance with the XML defined in Just-in doc.
</xs:documentation>
</xs:annotation>
<xs:choice maxOccurs="unbounded">
<xs:element name="id" type="atom:idType"/>
<xs:element name="link" type="atom:linkType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="link" type="atom:secondLinkType" minOccurs="1" maxOccurs="unbounded"/>
<xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attributeGroup ref="atom:commonAttributes"/>
</xs:complexType>
<xs:simpleType name="KnownRelCodeType">
<xs:restriction base="xs:string">
<xs:enumeration value="alternate">
<xs:annotation>
<xs:documentation>
The value "alternate" signifies that the IRI in the value of the href attribute identifies an alternate version of the resource described by the containing element.
</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SecondKnownRelCodeType">
<xs:restriction base="xs:string">
<xs:enumeration value="amphtml">
<xs:annotation>
<xs:documentation>
The value "amphtml" signifies that....
</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="RelCodeType">
<xs:union memberTypes="atom:KnownRelCodeType xs:string"/>
</xs:simpleType>
<xs:simpleType name="SecondRelCodeType">
<xs:union memberTypes="atom:SecondKnownRelCodeType xs:string"/>
</xs:simpleType>
<xs:complexType name="linkType" mixed="true">
<xs:annotation>
<xs:documentation>
The Atom link construct is defined in section 3.4 of the format spec.
</xs:documentation>
</xs:annotation>
<xs:attribute name="href" type="xs:anyURI" use="required"/>
<xs:attribute name="rel" type="atom:RelCodeType" use="required"/>
<xs:attribute name="type" type="xs:string" use="required"/>
<xs:attributeGroup ref="atom:commonAttributes"/>
</xs:complexType>
<xs:complexType name="secondLinkType" mixed="true">
<xs:annotation>
<xs:documentation>
complex type for link rel="amphtml"
</xs:documentation>
</xs:annotation>
<xs:attribute name="rel" type="atom:SecondRelCodeType" use="required"/>
<xs:attribute name="href" type="xs:anyURI" use="required"/>
<xs:attributeGroup ref="atom:commonAttributes"/>
<xs:element name="inline:inline" type="inline:inlineType"/>
<xs:attributeGroup ref="atom:commonAttributes"/>
</xs:complexType>
答案 0 :(得分:0)
不,XML兄弟元素的名称不能相同,但在XSD中输入的方式不同。
为元素赋予不同的名称,或者为两者使用相同的类型,可能使用可选性来适应各种类型所提供的可能性的结合。