【问题标题】:Cvc-complex-type.2.4.a: Invalid Content Was Found Starting With Element ' ' [duplicate]Cvc-complex-type.2.4.a:发现以元素“”开头的无效内容[重复]
【发布时间】:2020-10-31 07:13:10
【问题描述】:

我有一个对 XSD 无效的 XML 文件,但我不明白是什么问题! XML 似乎是正确的,但它是无效的

Cvc-complex-type.2.4.a: Invalid Content Was Found Starting With Element 'decodifica_impianto'. One Of '{decodifica_impianto}' Is Expected., Line '3', Column '24'.

这是我的XSD 结构:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://XXYYYYYZZZZZ"
    xmlns:aeeg="http://www.XXXXXX">
    <xs:element name="tr_cdgn">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" minOccurs="1" name="decodifica_impianto"
                    type="aeeg:tipo_decodifica_impianto"/>
                <xs:element maxOccurs="unbounded" minOccurs="0" name="dichiarazione_impianto">
                    <xs:annotation>
                        <xs:documentation>MASCHERA: Dichiarazione per impianto </xs:documentation>
                    </xs:annotation>
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element minOccurs="0" name="lunghezza_rete_non_norme_tecniche"
                                type="xs:integer"/>
                            <xs:element name="dichiarazioni_sensi_del_comma">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="controllo_compilazione">
                                            <xs:complexType>
                                                <xs:attribute name="codice_impianto" type="xs:int"/>
                                                <xs:attribute name="flag_compilazione_prec_1_2" type="xs:boolean"/>
                                                <xs:attribute name="flag_compilazione_prec_2" type="xs:boolean"/>
                                            </xs:complexType>
                                        </xs:element>
                                        <xs:element minOccurs="0" name="dt_anno_prec_2"
                                            type="xs:integer"/>
                                        <xs:element minOccurs="0" name="dt_anno_prec_1"
                                            type="xs:integer"/>
                                   </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="codice_impianto" type="xs:int" use="required"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:keyref name="fk_dichiarazione_impianto" refer="aeeg:pk_impianto">
            <xs:selector xpath="dichiarazione_impianto"/>
            <xs:field xpath="@codice_impianto"/>
        </xs:keyref>
        <xs:keyref name="fk_impianto_comp_dt_dta_clienti" refer="aeeg:pk_impianto_comp_dt_dta_clienti">
            <xs:selector xpath="dichiarazione_impianto/dichiarazioni_sensi_del_comma/controllo_compilazione"/>
            <xs:field xpath="@codice_impianto"/>
            <xs:field xpath="@flag_compilazione_prec_1_2"/>
            <xs:field xpath="@flag_compilazione_prec_2"/>
        </xs:keyref>

    </xs:element>
    <xs:complexType name="tipo_decodifica_impianto">
        <xs:sequence>
            <xs:element name="codice_impianto" type="xs:int"/>
            <xs:element maxOccurs="1" minOccurs="1" name="denominazione" type="xs:string"/>
            <xs:element name="flag_compilazione_prec_1_2" type="xs:boolean"/>
            <xs:element name="flag_compilazione_prec_2" type="xs:boolean"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>


这是我的XML 结构:

<?xml version="1.0" encoding="utf-8"?>
<tr_cdgn xmlns="WWW:XXYYYYZZ" xsi:schemaLocation="XXXXX" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <decodifica_impianto>
    <codice_impianto>676</codice_impianto>
    <denominazione>string</denominazione>
    <flag_compilazione_prec_1_2>true</flag_compilazione_prec_1_2>
    <flag_compilazione_prec_2>false</flag_compilazione_prec_2>
  </decodifica_impianto>
</tr_cdgn>

谁能帮我理解问题出在哪里? 问候 罪

【问题讨论】:

  • 您的 XSD 本身无效。它引用来自不可用命名空间的组件。如果您需要进一步的帮助,请创建一个完整 minimal reproducible example 来说明您的问题。
  • 另外,XML 文档的命名空间与 XSD 的目标命名空间不同。
  • 也许 XSD 无效,因为我应该剪切一些部分以便粘贴到站点中。但是命名空间的问题是什么?
  • 我这里也去掉了命名空间...所以它们在原文件中有相同的命名空间....
  • 错误提示“decodifica_impianto”是预期的,但我的 XML 文件中有它

标签: xml xsd xsd-validation xml-validation


【解决方案1】:

我找到了根本原因,我们需要在XS:schema中添加elementFormDefault="qualified"标签

【讨论】:

    猜你喜欢
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 2011-07-07
    • 2019-01-26
    • 2018-12-23
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    相关资源
    最近更新 更多