Attributes XSD中同一元素的内容限制和属性验证
我想验证元素“测试”是否应该Attributes XSD中同一元素的内容限制和属性验证,attributes,xsd,restriction,Attributes,Xsd,Restriction,我想验证元素“测试”是否应该 限制其内容(例如,使用模式限制),以及 包含某些属性(例如,“id”、“class”和“name”) 我正在编写的XSD如下所示: <xsd:element name="Test" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType mixed="true"> <xsd:simpleContent> <xsd:restriction>
- 限制其内容(例如,使用模式限制),以及
- 包含某些属性(例如,“id”、“class”和“name”)
<xsd:element name="Test" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType mixed="true">
<xsd:simpleContent>
<xsd:restriction>
<xsd:pattern value="xyz"/>
</xsd:restriction>
</xsd:simpleContent>
<xsd:attribute name="id" type="xsd:string"></xsd:attribute>
<xsd:attribute name="class" type="xsd:string"></xsd:attribute>
<xsd:attribute name="name" type="xsd:string"></xsd:attribute>
</xsd:complexType>
</xsd:element>
但是,当我在Visual Studio中编写此代码时,“xsd:attribute”元素出现以下错误:
“属性”和内容模型是互斥的
是否有方法验证同一元素上的内容限制和属性?您需要分离出限制并为其命名,然后将其作为扩展的基本类型引用。像这样:
<xsd:simpleType name="RestrictedString">
<xsd:restriction base="xsd:string">
<xsd:pattern value="xyz" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="Test">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="RestrictedString">
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="class" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
谢谢!这很有效。这也很方便,因为我想在其他地方重复使用限制。顺便说一句-我有多行内容的问题,但通过在模式后添加“”解决了这些问题。