Home > Software engineering >  Why is the XML error occurringcvc-complex-type.2.4.a: Invalid content was found starting with elemen
Why is the XML error occurringcvc-complex-type.2.4.a: Invalid content was found starting with elemen

Time:10-09

I have a table with 6 columns and want to create a XML for it, also for when just one is filled.

I have created an example XML by filling in all the 6 files;

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com) -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="AssetInterface">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="FysiekeID" type="xs:unsignedByte" nillable="true" minOccurs="1" />
        <xs:element name="BronID" type="xs:unsignedByte" nillable="true" minOccurs="1"  />
        <xs:element name="Bron" type="xs:string" nillable="true" minOccurs="1"/>
        <xs:element name="Status" type="xs:string" nillable="true" minOccurs="1"/>
        <xs:element name="Changed" type="xs:dateTime" nillable="true" minOccurs="1"/>
        <xs:element name="Created" type="xs:dateTime" nillable="true" minOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

With this I get a XML for a full filled object;

<?xml version='1.0' encoding='utf-8'?>
<AssetInterface>
    <FysiekeID>1</FysiekeID>
    <BronID>1</BronID>
    <Bron>SAP</Bron>
    <Status>Synchronised</Status>
    <Changed>2021-10-08T04:41:23.617Z</Changed>
    <Created>2021-10-07T20:19:57.003Z</Created>
</AssetInterface>

But when I want to create a XML just with the field for Status, I got an error;

<?xml version='1.0' encoding='utf-8'?><AssetInterface><Status>_New</Status></AssetInterface>

Error occurred while parsing xml: cvc-complex-type.2.4.a: Invalid content was found starting with element 'Status'. One of '{FysiekeID}' is expected.

I read several topics that the XSD should be changed, added those nilleable and minoccurs tags but still no difference. What is the correct way to handle this message?

CodePudding user response:

If you will change minOccurs="1" to minOccurs="0" , it will make the XML elements optional.

  •  Tags:  
  • xml
  • Related