我想验证元素'Test'应该
我写的XSD看起来像这样:
<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'元素上出现以下错误:
'属性'和内容模型是互斥的
有没有办法在同一元素上验证内容限制和属性?
答案 0 :(得分:13)
您需要将限制分开并为其命名,然后将其称为扩展的基本类型。像这样:
<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>