XSD 中同一元素的内容限制和属性验证
我想验证元素“Test”的
- 内容应受到限制(例如,使用模式限制),并且
- 包含某些属性(例如“id”、“class”和“name”)。
我正在编写的 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”元素上收到以下错误:
“属性”和内容模型是互斥的
有没有办法验证同一元素上的内容限制和属性?
I would like to validate that an element 'Test' should
- Have its content restricted (for example, using a pattern restriction), and
- Contain certain attributes (for example, 'id', 'class' and 'name').
The XSD I'm writing looks like this:
<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>
However, when I code this in Visual Studio, I get the following error on the 'xsd:attribute' elements:
'attribute' and content model are mutually exclusive
Is there a way to validate both a content restriction and attributes on the same element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要分离出您的限制并为其命名,然后将其作为扩展的基本类型引用。像这样:
You need to separate out your restriction and give it a name, then refer to it as a base type for an extension. Like this: