xsd :
HTML 테이블과 매우 유사합니다. 행에는 열과 열에 요소가 있습니다.C# 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>
내가 그 유효성을 검사하기 위해 노력하고있어 : 내가 갖는 다음
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));
을
<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>
그리고
다음과 같은 XML (나를 위해 유효한 XML이다)를 생성 예외 :The element 'col' has invalid child element 'textbox'. List of possible elements expected: 'label'
내 xsd 또는 C# 코드가 잘못 되었나요? (XML은 좋은 예입니다)? 내가 lable
가 label
과 동일하지 않습니다 생각
<lable>dddddd</lable>
:
xsl 대신 xsd : choice ... –
을 선택하십시오. @PetruGardea 좋은 지점, 나는 그것을 고쳤습니다. –