I'm trying to validate below XML with the below XSD:
XML
<Device xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Parameter Id="100" Flag="100" xsi:type="xsd:unsignedInt">-100</Parameter>
</Device>
XSD
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Device">
<xsd:complexType>
<xsd:sequence>
<xsd:element name='Parameter' type='paramType' minOccurs='0' maxOccurs='unbounded' />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="paramType">
<xsd:attribute name="Id" use="required"/>
<xsd:attribute name="Flag" use="required"/>
<xsd:anyAttribute processContents="lax"/>
</xsd:complexType>
</xsd:schema>
I'm facing 2 issues:
Unable to use xsd:unsignedInt
directly in XML with below error
Type 'xsd:unsignedInt' is not validly derived from the type definition, 'paramType', of element 'Parameter'
Unable to use both xsd:type
and other non-namespaced attributes at the same time
Element 'Parameter' is a simple type, so it cannot have attributes, excepting those whose namespace name is identical to 'http://www.w3.org/2001/XMLSchema-instance' and whose [local name] is one of 'type', 'nil', 'schemaLocation' or 'noNamespaceSchemaLocation'. However, the attribute, 'Flag' was found.
How do I edit my XSD to fix these issues. My final requirement is that all the Parameter
nodes should contain Id
and Flag
attributes and its value should be validated against type provided (in the actual XML itself).
Using xsi:type
inside xsd is not an option for me.