0
我有兩個具有相同名稱但具有不同屬性的子元素。有沒有辦法爲它寫一個有效的XSD。用於具有兩個相同名稱元素的XML的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>
嗨,我改變XML在這裏是不可能的。另外,我不能在這裏使用相同的類型,因爲我必須爲每個具有相同名稱的元素定義不同的屬性。你能舉一個你提供的建議的例子嗎?當你說「可能使用可選性來適應各種類型提供的可能性的聯合時,我無法理解」。 –