【问题标题】:XSD Non sense error. The attribute 'filter' is not allowedXSD 无意义错误。不允许使用“过滤器”属性
【发布时间】:2015-08-20 05:17:27
【问题描述】:

我得到了下一个 XML:

<!-- language: xml -->
<Message name="Msg1" type="SIMPLE">
    <Doc> message to send </Doc>
    <Parameters>
        <Parameter name="param1" type="byte" filter="2" mask="On">
            <Fields>
                <Field encode="hex">
                    <Values>
                        <Value name="INDICATOR" id="0"/>
                    </Values>
                </Field>
            </Fields>
        </Parameter>
        <Parameter name="param2" type="byte" filter="3" mask="On"/>
        <Parameter name="param3" type="byte"/>
    </Parameters>
</Message>

我的 XSD 文件就是这个:

    <xs:element name="Message" minOccurs="0" maxOccurs="unbounded">
        <xs:complexType>
            <xs:choice maxOccurs="unbounded">
                <xs:element ref="Doc" minOccurs="0"/>
                <xs:element name="Parameters" minOccurs="0">
                    <xs:complexType>
                        <xs:choice maxOccurs="unbounded">
                            <xs:element name="Parameter" minOccurs="0" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:choice maxOccurs="unbounded">
                                        <xs:element ref="Doc" minOccurs="0"/>
                                        <xs:element name="Fields" minOccurs="0">
                                            <xs:complexType>
                                                <xs:choice maxOccurs="unbounded">
                                                    <xs:element name="Field" minOccurs="0" maxOccurs="unbounded">
                                                        <xs:complexType>
                                                            <xs:choice maxOccurs="unbounded">
                                                                <xs:element ref="Doc" minOccurs="0"/>
                                                                    <xs:element name="Values" minOccurs="0">
                                                                    <xs:complexType>
                                                                        <xs:choice maxOccurs="unbounded">
                                                                            <xs:element ref="Doc" minOccurs="0"/>
                                                                                <xs:element name="Value" minOccurs="1" maxOccurs="unbounded">
                                                                                <xs:complexType>
                                                                                    <xs:attribute name="name" type="xs:string" use="required">
                                                                                        <xs:annotation>
                                                                                            <xs:documentation>Name of the value</xs:documentation>
                                                                                        </xs:annotation>
                                                                                    </xs:attribute>
                                                                                    <xs:attribute name="id" type="xs:string" use="required">
                                                                                        <xs:annotation>
                                                                                            <xs:documentation>The value</xs:documentation>
                                                                                        </xs:annotation>
                                                                                    </xs:attribute>
                                                                                </xs:complexType>
                                                                            </xs:element>
                                                                        </xs:choice>
                                                                    </xs:complexType>
                                                                </xs:element>
                                                            </xs:choice>
                                                            <xs:attribute name="encode" type="xs:string" default="hex">
                                                                <xs:annotation>
                                                                    <xs:documentation>encoding</xs:documentation>
                                                                </xs:annotation>
                                                            </xs:attribute>
                                                        </xs:complexType>
                                                    </xs:element>
                                                </xs:choice>
                                            </xs:complexType>
                                            <xs:unique name="unique_filed_name">
                                                <xs:selector xpath="Field"/>
                                                <xs:field xpath="@name"/>
                                            </xs:unique>
                                        </xs:element>
                                    </xs:choice>
                                    <xs:attribute name="name" type="xs:string" use="required"/>
                                    <xs:attribute name="type" type="xs:string"/>
                                    <xs:attribute name="filter" type="xs:string"/>
                                    <xs:attribute name="mask" type="xs:string"/>
                                </xs:complexType>
                            </xs:element>
                        </xs:choice>
                    </xs:complexType>
                    <xs:unique name="unique_parameter_name">
                        <xs:selector xpath="Parameter"/>
                        <xs:field xpath="@name"/>
                    </xs:unique>
                </xs:element>
            </xs:choice>
            <xs:attribute name="name">
                <xs:annotation>
                    <xs:documentation>Unique</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="type" type="MessageTypes" use="required">
                <xs:annotation>
                    <xs:documentation>Select a valid type</xs:documentation>
                </xs:annotation>
            </xs:attribute>
        </xs:complexType>
    </xs:element>

我毫无意义地收到了这个错误,因为我在 XSD 中添加了过滤器:

元素“参数”,属性“过滤器”:属性“过滤器”不是 允许。

谁能帮我解释一下为什么我遇到了这个似乎很难解决的错误?

【问题讨论】:

  • 投反对票,因为当问题(部分)得到回答时您没有跟进。您似乎有提出问题但不承认答案的历史。

标签: xml xsd schema


【解决方案1】:

当我将你的“模式”粘贴到 xs:schema 元素中并运行它时,我得到了

Error at xs:element on line 3 column 69 of test.xsd:
  Attribute @minOccurs is not allowed on element <xs:element>
Error at xs:element on line 3 column 69 of test.xsd:
  Attribute @maxOccurs is not allowed on element <xs:element>

这表明您的 xs:element 实际上不是顶级元素,因此我们没有看到全貌。

当我修复它时,我会遇到更多错误,例如:

on line 6 of test.xsd:
  The element {Doc} is referenced, but has not been declared
on line 77 of test.xsd:
  The type {MessageTypes} is referenced, but has not been declared

当我修复这些错误时,实例对架构有效。

我只能得出结论,在将您的真实代码削减到您发布的部分时,您无意中删除了错误的部分。

但我同意这个信息毫无意义。您使用的是什么 XSD 处理器?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-12
    • 2020-10-22
    • 2012-09-26
    • 2019-10-23
    • 1970-01-01
    • 2023-01-10
    相关资源
    最近更新 更多