XSD 不允许我在所有指标内无界 [英] XSD doesn't allow me to have unbounded inside all indicator

查看:13
本文介绍了XSD 不允许我在所有指标内无界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让 var1 中的无序列表变量出现两次而 var2 出现无限次(我的项目中的用例不同).该元素不允许我使用 maxOccurs.

I'm trying to make unordered list of variables in var1 occurs twice and var2 occurs infinite times (Use case in my project is different). The element does not allow me to use maxOccurs.

我正在尝试做的事情有什么解决办法吗?

Is there any work around for what I'm trying to do?

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="testcomment">
    <xs:complexType>
      <xs:all>
        <xs:element name="var1" type="xs:string" maxOccurs="2" />
        <xs:element name="var2" type="xs:integer" maxOccurs="unbounded" />
      </xs:all>
    </xs:complexType>
  </xs:element>
</xs:schema>

推荐答案

您尝试做的事情听起来像是列表中元素的类型如果不提前阅读可能会产生歧义,在这种情况下没有解决方法XSD 因为它可以描述的语言类别.

What you're trying to do sounds like the type of an element in your list might be ambiguous without reading-ahead, in which case there's no work around in XSD because of the classes of languages it can describe.

你能贴出你的 XSD 的相关部分吗?

Can you post up a the relevant part of your XSD?

更新:不,您不能用 XSD 做到这一点.例如此处.此约束有一个名称 - UPA,或唯一粒子属性约束.这完全与歧义有关,Microsoft 网站对存在的原因有很好的解释 这里.

Update: No, you can't do that with XSD. The rules about what you can put in an <xs:all> element are listed for example here. This constraint has a name - the UPA, or Unique Particle Attribution constraint. It's all to do with ambiguity and the Microsoft website has a good explanation of why is exists here.

您可以更改文档布局以消除对此类声明的需要,也可以使用更具表现力的模式语言,例如 放松NG.

You can either change your document layout to remove the need for this kind of declaration, or look to a more expressive schema language like RelaxNG.

这篇关于XSD 不允许我在所有指标内无界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆