-1

I have a XML file that is not valid respect to XSD but I can not understand what is the issue! It seems that XML is correct but It is not valid

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'.

This is my XSD structue:

<?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>


This is my XML structure:

<?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>

Can anyone help me to understand where is the issue? Regards Sin

sinaei
  • 491
  • 2
  • 5
  • 19
  • Your XSD itself is not valid. It references components from unavailable namespaces. If you'd like further help, create an ***complete*** [mcve] that illustrates your problem. – kjhughes Jul 10 '20 at 14:16
  • Also, the namespace of your XML document is not the same as the target namespace of your XSD. – kjhughes Jul 10 '20 at 14:21
  • Maybe the XSD is not valid, because I ought to cut some parts for pasting in the site. But what is the issue of namespace? – sinaei Jul 10 '20 at 14:44
  • I also remove the name space here... So they have the same namespace in the original file.... – sinaei Jul 10 '20 at 14:48
  • The error saying that "decodifica_impianto" is expected but I have it in my XML file – sinaei Jul 10 '20 at 14:48
  • Not going to engage in ongoing back-and-forth in comments. [edit] your question and add a ***complete*** [mcve] as requested (and required) if you'd like help. – kjhughes Jul 10 '20 at 15:59

1 Answers1

1

I found the root cause, we need to add elementFormDefault="qualified" tag in XS:schema

sinaei
  • 491
  • 2
  • 5
  • 19