I have an XML file which has contents as below
<?xml version="1.0" encoding="UTF-8"?>
<SETTINGS Version="1">
<CLEANING amount="40"/>
<CLEANING name="abcd"/>
<CLEANING initials="ABCD"/>
<MAINTENANCE state="on"/>
<MAINTENANCE temperature="F"/>
</SETTINGS>
I created an XSD schema for this XML using some tool which generated the below XSD output.
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="SETTINGS">
<xs:complexType>
<xs:sequence>
<xs:element name="CLEANING" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="amount" type="xs:unsignedByte" use="required" />
<xs:attribute name="name" type="xs:string" use="required" />
<xs:attribute name="initials" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="MAINTENANCE" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="state" type="xs:string" use="required" />
<xs:attribute name="temperature" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Version" type="xs:unsignedByte" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
Now when i try to validate this XMl against the XSD schema generated, i get below errors in validation(validated using some online validator).
Not valid.
Error - Line 3, 24: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 24; cvc-complex-type.4: Attribute 'name' must appear on element 'CLEANING'.
Error - Line 3, 24: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 24; cvc-complex-type.4: Attribute 'initials' must appear on element 'CLEANING'.
Error - Line 4, 24: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 24; cvc-complex-type.4: Attribute 'amount' must appear on element 'CLEANING'.
Error - Line 4, 24: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 24; cvc-complex-type.4: Attribute 'initials' must appear on element 'CLEANING'.
Error - Line 5, 28: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 28; cvc-complex-type.4: Attribute 'amount' must appear on element 'CLEANING'.
Error - Line 5, 28: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 28; cvc-complex-type.4: Attribute 'name' must appear on element 'CLEANING'.
Error - Line 6, 26: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 26; cvc-complex-type.4: Attribute 'temperature' must appear on element 'MAINTENANCE'.
Error - Line 7, 31: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 31; cvc-complex-type.4: Attribute 'state' must appear on element 'MAINTENANCE'.
Both XML and XSD are valid formats as validated online. I am not able to understand the reason behind this error. I suspect it is because ofhaving multiple elements sharing same name for which I think there is some constraint in generating the XSD schema. Not sure exactly what's wrong.
What am I doing wrong here and what could be solution for this error?