I defined a xsd:
Very similar to HTML table. rows has columns and columns has elements.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attributeGroup name="basics">
<xs:attribute name="title" type="xs:string" use="required"/>
<xs:attribute name="field_id" type="xs:string" use="required"/>
<xs:attribute name="is_mandatory" type="xs:boolean" use="required"/>
</xs:attributeGroup>
<xs:element name="form">
<xs:complexType>
<xs:sequence>
<xs:element name="row">
<xs:complexType>
<xs:sequence>
<xs:element name="col">
<xs:complexType>
<xs:sequence>
<!-- lable -->
<xs:element name="label" type="xs:string"/>
<!-- image -->
<xs:element name="image" >
<xs:complexType>
<xs:attribute name="src" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<!-- textbox -->
<xs:element name="textbox">
<xs:complexType>
<xs:attributeGroup ref="basics"/>
<xs:attribute name="hint" type="xs:string" use="optional" default=""/>
</xs:complexType>
</xs:element>
<!-- yesno -->
<xs:element name="yesno">
<xs:complexType>
<xs:attributeGroup ref="basics"/>
</xs:complexType>
</xs:element>
<!-- calendar -->
<xs:element name="calendar">
<xs:complexType>
<xs:attributeGroup ref="basics"/>
</xs:complexType>
</xs:element>
<!-- Select/ multi select -->
<xs:element name="select">
<xs:complexType>
<xs:sequence>
<xs:element name="option"/>
</xs:sequence>
<xs:attributeGroup ref="basics"/>
<xs:attribute name="singleChoice" type="xs:boolean" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="title" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
And created the following xml (for me is a valid xml):
<?xml version="1.0" encoding="utf-8" ?>
<form title="title">
<row>
<col>
<textbox title="aaa" field="Name" mandatory="false" hint="aaa"/>
</col>
</row>
<row>
<col>
<textbox title="bbb" field="UID" mandatory="true" hint="bbb"/>
<yesno title="dddddd" field="field-yesno" mandatory="true"/>
</col>
</row>
<row>
<col>
<lable>dddddd</lable>
</col>
</row>
<row>
<col>
<calendar title="cccc" field="StartDate" mandatory="true"/>
</col>
</row>
<row>
<col>
<select title="select" field="ffff" mandatory="true">
<option value="1">option 1</option>
<option value="2" selected="true">option 2</option>
<option value="3">option 3</option>
</select>
</col>
</row>
</form>
When I'm trying to validate that:
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(null, getAbsolutePath("xml\\form_schema.xsd"));
settings.ValidationType = ValidationType.Schema;
settings.CloseInput = true;
settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings |
XmlSchemaValidationFlags.ProcessIdentityConstraints |
XmlSchemaValidationFlags.ProcessInlineSchema |
XmlSchemaValidationFlags.ProcessSchemaLocation;
// create xml reader
XmlReader reader = XmlReader.Create(new StringReader(xml), settings);
XmlDocument document = new XmlDocument();
document.Load(reader);
document.Validate(new ValidationEventHandler(ValidationHandler));
I'm getting the following exception:
The element 'col' has invalid child element 'textbox'. List of possible elements expected: 'label'
Whats wrong with my xsd or C# code ? (the xml is good example) ?