如何向 xsd:any 元素添加属性
如何向 xsd:any 元素添加属性?例如,给定以下内容:
<xsd:element name="requests">
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace="http://xxx.yyy.com" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
如何将其作为属性添加到 any 中,以便可以针对架构验证以下 xml 而不会出现错误:
<requests>
<operation count="1">
<requests>
How do you add an attribute to an xsd:any element? For example, given the following:
<xsd:element name="requests">
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace="http://xxx.yyy.com" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
How do you add as an attribute to any so that the following xml can be validated against the schema without errors:
<requests>
<operation count="1">
<requests>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
xsd:any 不能包含任何属性声明,因为它本质上允许在序列中声明命名空间“http://xxx.yyy.com”中定义的任何元素。如果您不使用单独的 XSD 来验证该命名空间,则只需使用以下内容代替 xsd:any:
否则,您将需要在以下位置声明“http://xxx.yyy.com”的命名空间前缀 : XSD 顶部并引用该架构中的元素而不是 xsd:any。因此,如果“http://xxx.yyy.com”的架构包含以下声明:
那么您可以在 XSD 中引用此类型:
xsd:any cannot include any attribute declarations, because it essentially allows any element that is defined within the namespace "http://xxx.yyy.com" to be declared within the sequence. If you are not using a separate XSD to validate that namespace, then you can simply use the following in place of xsd:any:
Otherwise, you will want to declare a namespace prefix for "http://xxx.yyy.com" at the top of your XSD and refer to the element within that schema instead of xsd:any. So, if the schema for "http://xxx.yyy.com" includes the following declaration:
Then you could reference this type in your XSD:
如果您说您希望允许任何具有 count 属性的元素作为子元素,那么您在 XSD 1.0 中无法做到这一点。您可以在 XSD 1.1(目前在 Saxon 和 Xerces 中受支持)中使用断言来完成此操作:
If you're saying you want to allow any element as a child so long as it has a count attribute, then you can't do that in XSD 1.0. You can do it in XSD 1.1 (currently supported in Saxon and Xerces) with an assertion: