Below is the xml , of which i need to create an xml schema(xsd file) validating the field name i.e. in the tableData node(in below xml), the first column name should be "field" with the key as "name" and its value should be "Data1".I also want to validate that the value of this column should be of type xs:integer(as value is 123). Similarly need for all the columns of the table.I am new to xml validation so facing issues.
XML:
<table name="Employee">
<tableData>
<field name="Data1">123</field>
<field name="Data2">234</field>
<field name="Data3">Y</field>
<field name="Data4">321</field>
</tableData>
</table>
I tried to create the schema but failed to validate the type of 123 (i.e. xs:integer) and other column types.Please if someone can provide a hint on this.
Schema which I tried:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="tableData" >
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="4" name="field" type="fieldType" minOccurs="4"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="fieldType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="validAttributeType" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="validAttributeType">
<xs:restriction base="xs:string">
<xs:enumeration value="Data1"/>
<xs:enumeration value="Data2"/>
<xs:enumeration value="Data3"/>
<xs:enumeration value="Data4" />
</xs:restriction>
</xs:simpleType>
</schema>
Also, for table name= "Employee" in xml( First line in xml) , I tried to create a schema and add it before the schema I mentioned above but that gives error: The element 'table' cannot contain child element 'tableData' because the parent element's content model is text only. Schema which I was adding above the schema mentioned above is:
<xs:element name="table" type="mTable"/>
<xs:complexType name="mTable" >
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string" fixed="Employee"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>