cvc-complex-type.2.4.a:发现以元素 'param' 开头的无效内容。应为“{param}”之一
cvc-complex-type.2.4.a: Invalid content was found starting with element 'param'. One of '{param}' is expected
以下是我的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 时,出现上述错误。我做错了什么?
您可能希望参数位于架构的目标命名空间中,在这种情况下,您应该将 elementFormDefault="qualified"
添加到 xs:schema 元素。
这几乎总是可以使用的正确设置。不幸的是,XSD 设计师将默认值弄错了。
这也是一条糟糕的错误消息:如果您使用的是撒克逊语,它会说
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
以下是我的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 时,出现上述错误。我做错了什么?
您可能希望参数位于架构的目标命名空间中,在这种情况下,您应该将 elementFormDefault="qualified"
添加到 xs:schema 元素。
这几乎总是可以使用的正确设置。不幸的是,XSD 设计师将默认值弄错了。
这也是一条糟糕的错误消息:如果您使用的是撒克逊语,它会说
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