xml - xs:any 可以在 XSD 中的 xs:all 元素中吗?
问题描述
我正在尝试从提供的 XSD 生成数据合同。 Svcutil.exe
向我抛出这个错误:
'http://www.w3.org/2001/XMLSchema:any'
在这种情况下不支持该元素。”
在 XSD 中查看,类型元素any
出现了两次。这是它第一次出现。
<xs:element minOccurs="0" maxOccurs="1" name="Markup">
<xs:complexType>
<xs:all>
<xs:any processContents="lax" />
</xs:all>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
从我对此的研究来看,似乎xs:any
不能在一个xs:all
元素中。但我找不到明确表明这一点的规范或等效物。
可以xs:any
出现在一个xs:all
?还是无效?
解决方案
XSD 1.0
不,xs:any
不能在xs:all
XSD 中:
<all
id = ID
maxOccurs = 1 : 1
minOccurs = (0 | 1) : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, element*)
</all>
但xs:any
可以在 a xs:choice
or中xs:sequence
:
<choice
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>
<sequence
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (element | group | choice | sequence | any)*)
</sequence>
因此,您可以改为将您的包装xs:all
在xs:choice
orxs:sequence
中,例如:
<xs:element minOccurs="0" maxOccurs="1" name="Markup">
<xs:complexType>
<xs:sequence>
<xs:any processContents="lax" />
</xs:sequence>
</xs:complexType>
</xs:element>
并且您的 XSD 遵守允许的内容模型。
XSD 1.1
是的,xs:any
可以在xs:all
XSD 中:
<all
id = ID
maxOccurs = (0 | 1) : 1
minOccurs = (0 | 1) : 1
{any attributes with non-schema namespace . . .}>
Content: (annotation?, (element | any | group)*)
</all>
但是,请注意 XSD 处理器必须符合XSD 1.1;您发布的错误表明您的工具仅支持XSD 1.0。
推荐阅读
- sql - SQL:在 CTE 内建立一个可变输入数字的数字表
- java - 如何遍历对角线?
- python - 在 Flask 中读取 CSV 文件并在 HTML 表格中显示 CSV 文件中的值
- web-development-server - 如何允许用户上传文件到网站?
- c++ - Visual Studio Code - 命名空间生成关闭
- c# - 使用 Polly .Net 实施 Retry + Timeout + CircuitBreaker 弹性策略的正确方法是什么?
- r - 如何在 r 中选择/子集我的数据集中的某些日期
- c - 为什么在读取文件时使用 feof 进行两次检查?
- python - Python:对 Python 列表进行排序以显示最常见到最不常见的字符串以及它出现的次数
- excel - 在 Excel vb 中读取 ArrayList 项时出现“类型不匹配”错误。为什么?