我得到了下一个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中添加了过滤器:
元素'参数',属性'过滤器':属性'过滤器'不是 允许的。
任何人都可以帮我解释为什么我得到这个似乎很难解决的错误?
答案 0 :(得分:0)
当我粘贴&#34;架构&#34;进入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:元素实际上并不是顶级元素,所以我们看不到整体情况。
当我解决这个问题时,我会收到更多错误,例如:
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处理器是什么?