cvc-complex-type.2.4.a:从元素'param'开始发现无效内容。预计会有一个'{param}'

时间:2015-03-06 09:22:27

标签: xml eclipse xsd

以下是我的xsd和xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://example.com/DashboardSchema" xmlns:tns="http://example.com/DashboardSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="dashboard" type="tns:xmlDashboard"/>

  <xs:complexType name="xmlDashboard">
    <xs:sequence>
      <xs:element name="param" type="tns:xmlDashboardParameter" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="xmlDashboardParameter">
    <xs:sequence/>
    <xs:attribute name="module" type="xs:int" use="required"/>
    <xs:attribute name="node" type="xs:int" use="required"/>
    <xs:attribute name="parameter" type="xs:int" use="required"/>
  </xs:complexType>
</xs:schema>


<dashboard xmlns="http://example.com/DashboardSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://example.com/DashboardSchema ./schema3.xsd">
    <param module="1" node="1" parameter="4" />
    <param module="1" node="2" parameter="6" />
    <param module="2" node="0" parameter="4" />
    <param module="2" node="0" parameter="5" />
</dashboard>

当我尝试在Eclipse中验证xml时,我得到了上面提到的错误。我做错了什么?

1 个答案:

答案 0 :(得分:2)

您可能希望param位于架构的targetNamespace中,在这种情况下,您应该将elementFormDefault="qualified"添加到xs:schema元素中。

这几乎总是正确的设置。不幸的是,XSD设计师得到了默认错误。

这也是一个糟糕的错误信息:如果您使用Saxon,它会说

Validation error on line 4 of test.xml:
  XSD: In content of element <dashboard>: The content model does not allow element
  <Q{.../DashboardSchema}param> to appear as the first child. The element is in namespace
  http://example.com/DashboardSchema but it should be in no namespace. 
  Validating /dashboard[1]/param[1]
  See http://www.w3.org/TR/xmlschema11-1/#cvc-complex-type clause 2.4