I would like to create XML Schema for this chunk of xml, I would like to restrict the values of "name" attribute, so that in output document on and only one instance of day is allowed for each week day:<a> <day name="monday" /> <day name="tuesday" /> <day name="wednesday" /></a>我曾尝试使用这个: <xs:complexType name="a"> <xs:sequence> <xs:element name="day" minOccurs="1" maxOccurs="1"> <xs:complexType> <xs:attribute name="name" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="monday" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> <xs:element name="day" minOccurs="1" maxOccurs="1"> <xs:complexType> <xs:attribute name="name" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="tuesday" /> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element> </xs:sequence></xs:complexType>但是 Eclipse 中的 XML Schema 验证器显示错误模型组中出现多个名称为 'day' 且类型不同的元素.".but XML Schema validator in eclipse says error "Multiple elements with name 'day', with different types, appear in the model group.".还有什么办法吗?推荐答案你需要这样的东西:<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="a"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" ref="day"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="day"> <xs:complexType> <xs:attribute name="name" use="required"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="monday"/> <xs:enumeration value="tuesday"/> <xs:enumeration value="wednesday"/> </xs:restriction> </xs:simpleType> </xs:attribute> </xs:complexType> </xs:element></xs:schema> 这篇关于如何在 XML Schema 中定义多个具有相同名称和不同属性值的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-07 01:11