使用expected元素找到的XML Schema无效内容

时间:2014-02-12 21:20:24

标签: xml xsd

我有一个XML模式片段,如下所示:

<xsd:complexType name="CustomStreamHandlerConfig">
    <xsd:complexContent>
        <xsd:extension base="AbstractStreamHandlerConfig">
            <xsd:choice>
                <xsd:sequence>
                    <xsd:element name="class" type="xsd:string" />
                    <xsd:group ref="CustomParameters" />
                    <xsd:group ref="NextElements" minOccurs="0" maxOccurs="unbounded" />
                </xsd:sequence>
                <xsd:element name="config-file" type="xsd:anyURI" />
            </xsd:choice>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

基本上,此模式允许XML片段使用一些参数(类,自定义参数等)或配置文件URI来描述CustomStreamHandlerConfig

CustomParameters组允许任意数量的single-params元素列表和任意数量的multiple-params列表:

<xsd:group name="CustomParameters">
    <xsd:sequence>
        <xsd:element name="single-params" type="KeyValue" minOccurs="0" maxOccurs="unbounded" />
        <xsd:element name="multiple-params" type="KeyMultipleValues" minOccurs="0" maxOccurs="unbounded" />
    </xsd:sequence>
</xsd:group>

KeyValueKeyMultipleValues复杂类型如下:

<xsd:complexType name="KeyValue">
    <xsd:simpleContent>
        <xsd:extension base="xsd:string">
            <xsd:attribute name="key" type="xsd:string" use="required" />
        </xsd:extension>
    </xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="KeyMultipleValues">
    <xsd:sequence>
        <xsd:element name="value" minOccurs="2" maxOccurs="unbounded" />
    </xsd:sequence>
    <xsd:attribute name="key" type="xsd:string" use="required" />
</xsd:complexType>

当我尝试汇编表示CustomStreamHandlerConfig

的XML片段时
<custom-stream-retriever>
    <class>MyCustomStreamHandler</class>
    <single-params key="single-key">single-value</single-params>
    <mutiple-params key="multiple-key"> <!-- Invalid content -->
        <value>multiple-value</value>
        <value>multiple-value</value>
    </mutiple-params>
</custom-stream-retriever>

我收到cvc-complex-type.2.4.a: Invalid content was found starting with element 'mutiple-params'.错误。

问题是,当我检查预期元素列表时,我发现:One of '{..., "SomeNamespace":multiple-params, ...}' is expected.

我将SomeNamespace(示例命名空间名称)与模式文件中的targetNamespace进行了比较,它们都是相同的。我还必须确保xsd:schema代码具有elementFormDefault="qualified"

为什么XML文件拒绝mutiple-params元素?

1 个答案:

答案 0 :(得分:2)

不确定这是一个技巧问题,还是一个错字......你的XSD描述了multiple-params,而你的XML使用mutiple-params - 那里有一个l(小写L)后者。