一
一般應用都有自己的配置文件
二
源文件如下
<?xml version=
<xs:schema id=
<xs:complexType name=
<xs:sequence/>
<xs:attribute name=
<xs:attribute name=
<xs:attribute name=
<xs:attribute name=
</xs:complexType>
<xs:complexType name=
<xs:sequence />
<xs:attribute name=
<xs:attribute name=
<xs:attribute name=
</xs:complexType>
<xs:element name=
<xs:complexType>
<xs:sequence>
<xs:element name=
<xs:element name=
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
xsd
//
// <autogenerated>
// This code was generated by a tool
// Runtime Version:
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated
// </autogenerated>
//
using System
//
// This source code was auto
//
namespace ConfigDll
{
/// <remarks/>
[System
[System
[System
public class statements
{
private select[] selectField;
private update[] updateField;
/// <remarks/>
[System
public select[] select
{
get
{
return this
}
set
{
this
}
}
/// <remarks/>
[System
public update[] update
{
get
{
return this
}
set
{
this
}
}
}
/// <remarks/>
[System
[System
public class select
{
private string idField;
private string resultMapField;
private string cacheModelField;
private string sqlField;
/// <remarks/>
[System
public string id
{
get
{
return this
}
set
{
this
}
}
/// <remarks/>
[System
public string resultMap
{
get
{
return this
}
set
{
this
}
}
/// <remarks/>
[System
public string cacheModel
{
get
{
return this
}
set
{
this
}
}
/// <remarks/>
[System
public string sql
{
get
{
return this
}
set
{
this
}
}
}
/// <remarks/>
[System
[System
public class update
{
private string idField;
private string parameterMapField;
private string sqlField;
/// <remarks/>
[System
public string id
{
get
{
return this
}
set
{
this
}
}
/// <remarks/>
[System
public string parameterMap
{
get
{
return this
}
set
{
this
}
}
/// <remarks/>
[System
public string sql
{
get
{
return this
}
set
{
this
}
}
}
}
#region Using directives
using System;
using System
using System
using System
using System
using System
using System
using System
using System
#endregion
namespace ConfigDll
{
public class MyConfigHandler : IConfigurationSectionHandler
{
private Type _configType = typeof(statements);
private string _schemaResourceName =
private string _schemaNamespace =
public MyConfigHandler()
{
}
public object Create(object parent
{
XmlSerializer ser = new XmlSerializer(_configType);
// Create the XmlSchemaSet class
XmlSchemaSet sc = new XmlSchemaSet();
// Add the schema to the collection
Stream schemaStream = Assembly
sc
// Set the validation settings
XmlReaderSettings settings = new XmlReaderSettings();
settings
settings
settings
XmlReader reader = XmlReader
return ser
}
public void ValidationEventHandle(object sender
{
Console
}
}
}
當然你可以建一個通用的校驗類
如果使用VS
<?xml version=
<configuration>
<configSections>
<section name=
</configSections>
<stat
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27083.html