How can we write XSD schema for below XML using XSD 1.1 because using XSD 1.0 I am facing some issue as we are using same element name with diff types(attribute name and types) which is invalid and ambiguous in XSD 1.0 and I think in XSD 1.1 there could be some way (may be alternatives/assertions)to get a work around for this issue.
<?xml version="1.0" encoding="UTF-8"?>
<SETTINGS>
<CLEANING amount="40"/>
<CLEANING name="abcd"/>
<CLEANING value="0.01"/>
</SETTINGS>
Unfortunately we can not change XML format(which containes multiple elements with diff attribute types) and we need to write XSD schema for this XML with restrictions on attribute values.
As per the comments below created schema as below but still getting error in validation of above xml.
<!-- Created with Liquid Studio 2018 (https://www.liquid-technologies.com) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="SETTINGS" type="settingsType"/>
<xs:element name="CLEANING" type="cleaningType">
<xs:alternative type="amountType" test="exists(@amount)"/>
<xs:alternative type="nameType" test="exists(@name)"/>
<xs:alternative type="valueType" test="exists(@value)"/>
</xs:element>
<xs:complexType name="settingsType">
<xs:sequence>
<xs:element ref="CLEANING" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<!-- Base type -->
<xs:complexType name="cleaningType">
</xs:complexType>
<!-- Type amount -->
<xs:complexType name="amountType">
<xs:complexContent>
<xs:extension base="cleaningType">
<xs:attribute name="amount" type="xs:integer" use="required"/>
<xs:anyAttribute />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- Type name -->
<xs:complexType name="nameType">
<xs:complexContent>
<xs:extension base="cleaningType">
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:anyAttribute />
</xs:extension>
</xs:complexContent>
</xs:complexType>
<!-- Type value -->
<xs:complexType name="valueType">
<xs:complexContent>
<xs:extension base="cleaningType">
<xs:attribute name="value" type="xs:float" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Errors Severity Location Filename Message
7:66 schema.xsd s4s-elt-must-match.1: The content of 'CLEANING' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: alternative.
4:24 sample.xml cvc-complex-type.3.2.2: Attribute 'name' is not allowed to appear in element 'CLEANING'.