【问题标题】:XSD Schema Validation IssueXSD 架构验证问题
【发布时间】:2015-04-20 09:07:03
【问题描述】:

我有一个无法验证的架构的 sn-p。

<?xml version="1.1" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:group name="colorrgbGroup">
    <xs:all>
        <xs:element name="r" type="xs:unsignedShort" minOccurs="1" maxOccurs="1"/>
        <xs:element name="g" type="xs:unsignedShort" minOccurs="1" maxOccurs="1"/>
        <xs:element name="b" type="xs:unsignedShort" minOccurs="1" maxOccurs="1"/>
        <xs:element name="a" type="xs:unsignedShort" minOccurs="0" maxOccurs="1"/>
    </xs:all>
</xs:group>

<xs:group name="colornameGroup">
    <xs:all>
        <xs:element name="colorName" type="xs:normalizedString" minOccurs="1" maxOccurs="1"/>
        <xs:element name="a" type="xs:unsignedShort" minOccurs="0" maxOccurs="1"/>
    </xs:all>
</xs:group>

<xs:group name="colorpresetGroup">
    <xs:all>
        <xs:element name="preset" type="xs:normalizedString" minOccurs="1" maxOccurs="1"/>
        <xs:element name="a" type="xs:unsignedShort" minOccurs="0" maxOccurs="1"/>
    </xs:all>
</xs:group>

<xs:element name="color">
    <xs:complexType>
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:group ref="colorpresetGroup"/>
            <xs:group ref="colornameGroup"/>
            <xs:group ref="colorrgbGroup"/>
        </xs:choice>
    </xs:complexType>
</xs:element>
</xs:schema>

我想说的是元素颜色作为一个孩子有三个可能的组之一,并且一次只能有一个选项。如您所见,所有三个选项都将 Alpha 通道作为可选选项。

如果我将 '' 标签更改为 '' 标签,它会正确验证。但是对于“colorrgbGroup”,我们希望用户能够放置 RGBA、ABGR、ARGB、BGRA 等,因此我们更喜欢使用 '' 而不是 ''。

我正在使用这个website 来检查我的验证。

'' 中的每个 '' 选项都会给我以下错误。

错误 - 第 30、51 行:org.xml.sax.SAXParseException;行号:30; columnNumber: 51 cos-all-limited。 1.2:“所有”模型组必须 出现在 '{'min 发生'}' = '{'max occur'}' = 1 的粒子中,并且 该粒子必须是构成“{”内容的对的一部分 type'}' 的复杂类型定义。

我之前处理过模式并修改了现有模式,但这是我第一次真正从头开始编写。非常感谢任何帮助!

谢谢! 托德

【问题讨论】:

    标签: xml xsd-validation


    【解决方案1】:

    基本上,您不能将 xs:all 与 xs:choice 或 xs:sequence 混合使用。如果您的内容模型使用 xs:all,那么这就是它可以使用的全部内容。

    规则名称 cos-all-limited kind-of 总结起来......

    即使各组之间没有共同的元素,也不允许这样做,因此问题不仅仅是模棱两可(遇到“a”作为第一个孩子并且不知道要使用哪个组)。这只是你不能做的事情。

    【讨论】:

    • 谢谢,我担心可能是这种情况。
    猜你喜欢
    • 2012-05-29
    • 2010-11-15
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 2011-05-30
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    相关资源
    最近更新 更多