I would like to validate text values of an element based on attribute value. For example
<Device xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Parameter xsi:type="xsd:unsignedInt">-100</Parameter>
<Parameter xsi:type="xsd:boolean"></Parameter>
<Parameter>hello</Parameter>
</Device>
Both the above should fail. For boolean, anything shouldn't be accepted except "true" or "false" (even empty string)
My xml is much more complex with lot of Object
and Parameter
nodes and this is my xsd which is validating all those nodes recursively
<xs:complexType name="deviceType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Object"/>
<xs:element ref="Parameter"/>
</xs:choice>
</xs:complexType>
<xs:complexType name="objType">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Object"/>
<xs:element ref="Parameter"/>
</xs:choice>
<!-- Add all valid attributes for 'Object' type here -->
<xs:attribute name="Id" use="required"/>
<xs:attribute name="Flag" use="required"/>
<xs:anyAttribute processContents="lax"/>
</xs:complexType>
<xs:complexType name="paramType" mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Object"/>
<xs:element ref="Parameter"/>
</xs:choice>
<xs:attribute name="Id" use="required"/>
<xs:attribute name="Flag" use="required"/>
<xs:anyAttribute processContents="lax"/>
</xs:complexType>
But I'm facing this error.
Type 'xsd:unsignedInt' is not validly derived from the type definition, 'paramType', of element 'Parameter'.
Type 'xsd:unsignedInt' is not validly derived from the type definition, 'paramType', of element 'Parameter'.
How can I fix this?