After Using the Restriction validation gives error Unknown Node: Restriction I am not able to find the error. Can anybody help me out in XSD. this is my XML :
<?xml version="1.0" encoding="UTF-8"?>
<DataChannelconfig>
<DataTypeVersion>1</DataTypeVersion>
<FileformatVersion>0</FileformatVersion>
<DataChannel>
<Name>Supply Pump Flow Speed</Name>
<Datatype>Numeric</Datatype>
<Tag>Supply_Pump_Flow_Speed</Tag>
<Graph>
<Enable>0</Enable>
<AxisNo>0</AxisNo>
<Colour>255.0.225</Colour>
</Graph>
<Table>
<Enable>1</Enable>
<Table-ID>0</Table-ID>
<Table-Row>9</Table-Row>
<Unit>ml/min</Unit>
</Table>
</DataChannel>
</DataChannelconfig>
This is My XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="DataChannelconfig">
<xs:complexType>
<xs:sequence>
<xs:element name="DataTypeVersion" type="xs:byte"/>
<xs:element name="FileformatVersion" type="xs:byte" />
<xs:element name="DataChannel" type="xs:string">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:attribute name="Name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9_.'!@#$%^*()]{20}"/
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:element name="Datatype" type="xs:string"/>
<xs:attribute name="Datatype">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9_.'!@#$%^*()]{20}"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:element name="Tag" type="xs:string"/>
<xs:attribute name="Datatype">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9_.'!@#$%^*()]{20}"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:element name="Graph">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="Enable"/>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
<xs:element type="xs:byte" name="AxisNo"/>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
<xs:element type="xs:string" name="Colour"/>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{3}[.][0-9]{3}[.][0-9]{3}"/>
</xs:restriction>
</xs:sequence>
</xs:complexType>
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:byte" name="Enable"/>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
<xs:element type="xs:byte" name="Table-ID"/>
<xs:restriction base="xs:byte">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="3"/>
</xs:restriction>
<xs:element type="xs:string" name="Table-Row"/>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="14"/>
</xs:restriction>
<xs:element type="xs:string" name="Unit"/>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9_.'!@#$%^*()]{20}"/>
</xs:restriction>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
What is wrong in my XSD file?
Using Visual Studio trying to open your schema I got
Failed to load schema.
Reason : The 'http://www.w3.org/2001/XMLSchema:attribute' element is not supported in this contex
The problems are
You have declared both Elements and Attributes with the same name in the sequence. Attributes should reside outside of (after) the sequence. But your sample does not have any attributes, so I have removed them.
You have forgotten the closing > on this line
<xs:pattern value="[a-zA-Z0-9_.'!@#$%^*()]{20}"/
The element Graph is missing a closing tag
The elements, Enable, AxisNo & Colour etc. are self terminated, they need to be terminated after the restriction which needs to be wrapped by a type nodes rather than the type declared on the element.
This is what is should look like.
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="DataChannelconfig">
<xs:complexType>
<xs:sequence>
<xs:element name="DataTypeVersion" type="xs:byte"/>
<xs:element name="FileformatVersion" type="xs:byte" />
<xs:element name="DataChannel">
<xs:complexType>
<xs:sequence>
<xs:element name="Name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9_.'!@#$%^*()]{20}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Datatype">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9_.'!@#$%^*()]{20}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Tag" type="xs:string"/>
<xs:element name="Graph">
<xs:complexType>
<xs:sequence>
<xs:element name="Enable">
<xs:simpleType>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="AxisNo">
<xs:simpleType>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Colour">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{3}[.][0-9]{3}[.][0-9]{3}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="Enable">
<xs:simpleType>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Table-ID">
<xs:simpleType>
<xs:restriction base="xs:byte">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Table-Row">
<xs:simpleType>
<xs:restriction base="xs:byte">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="14"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Unit">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9_.'!@#$%^*()]{20}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Using the above schema against your sample gives the following output
The 'Name' element is invalid - The value 'Supply Pump Flow Speed' is invalid according to its datatype 'String' - The Pattern constraint failed.
The 'Datatype' element is invalid - The value 'Numeric' is invalid according to its datatype 'String' - The Pattern constraint failed.
The 'Colour' element is invalid - The value '255.0.225' is invalid according to its datatype 'String' - The Pattern constraint failed.
The 'Table-ID' element is invalid - The value '0' is invalid according to its datatype 'Byte' - The MinInclusive constraint failed.
The 'Unit' element is invalid - The value 'ml/min' is invalid according to its datatype 'String' - The Pattern constraint failed.