バージョン

EnforceXsdConstraints(Stream) メソッド

ストリームに含まれる XSD スキーマ内で見つかった制約をグリッドのバンドと列に適用します。
シンタックス
'宣言
 
Public Overloads Sub EnforceXsdConstraints( _
   ByVal stream As Stream _
) 
public void EnforceXsdConstraints( 
   Stream stream
)

パラメータ

stream
XSD スキーマを含むストリーム。
解説

このメソッドに渡す XSD スキーマは次の条件を満たしている必要があります。

  1. XSD 名前空間 ("http://www.w3.org/2001/XMLSchema") は、それに関連するプリフィックス ('xs' または 'xsd' など) を持つ必要があります。
  2. スキーマのターゲット名前空間はデフォルト名前空間 (つまり、プレフィックスを関連付けることができない) である必要があります。

このオーバー読み込みは All を使用して、どの制約を適用するかを指定します。

使用例
' simpleSchema.xsd
' ******************************************************************************
<xs:schema  targetNamespace="http://tempuri.org/simpleSchema.xsd"
			elementFormDefault="qualified"
			xmlns="http://tempuri.org/simpleSchema.xsd"			
			xmlns:xs="http://www.w3.org/2001/XMLSchema" 
			xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">			
    <xs:element name="MyDataSet" msdata:IsDataSet="true">
		<xs:complexType>
			<xs:choice maxOccurs="unbounded">
				<!-- Declares a table of data called "People" which must have between 1 and 5 rows of data. -->			
				<xs:element name="People" minOccurs="1" maxOccurs="5">
					<xs:complexType>
						<xs:sequence>						
							<!-- Declares a column called "Name" of type string where the 
							     length of the value must be at most 30 characters.  Setting 
							     'minOccurs' to 1 indicates that cells in this column cannot be empty/null. -->
							<xs:element name="Name" minOccurs="1">
								<xs:simpleType>
									<xs:restriction base="xs:string">
										<xs:maxLength value="30" />
									</xs:restriction>
								</xs:simpleType>
							</xs:element>
							
							<!-- Declares a DateTime column called "DateOfBirth". -->
							<xs:element name="DateOfBirth"  type="xs:dateTime" />							
						</xs:sequence>
						
						<!-- Declares a column called "IsFamous" which is represented in XML as an attribute. -->
						<xs:attribute name="IsFamous" type="xs:boolean" />						
					</xs:complexType> 
				</xs:element>
			</xs:choice>					
		</xs:complexType>				
    </xs:element>                         
</xs:schema>

' MyApp.cs
' ******************************************************************************
Private Sub SetupGrid()
   ' Create a DataSet and then read its structure in from the XSD schema file.
   '
   Dim ds As New DataSet()
   ds.ReadXmlSchema("..\simpleSchema.xsd")
   
   ' Get a reference to the "People" table.
   '
   Dim tbl As DataTable = ds.Tables("People")
   
   ' Add a few rows of data: People(IsFamous, Name, DateOfBirth)
   '
   tbl.Rows.Add(New Object() {True, "Ludwig Van Beethoven", New DateTime(1770, 12, 17)})
   tbl.Rows.Add(New Object() {False, "Joe Nobody", New DateTime(1972, 11, 2)})
   tbl.Rows.Add(New Object() {True, "Pablo Picasso", New DateTime(1881, 10, 25)})
   
   ' Bind the grid to the DataSet object.
   '
   Me.ultraGrid1.DataSource = ds

   ' Allow for new rows to be added.
   '
   Me.ultraGrid1.DisplayLayout.Override.AllowAddNew = AllowAddNew.TemplateOnBottom
   
   ' Inform the grid that it should enforce the constraints found in the XSD schema
   ' which are not honored by the DataSet.
   '
   Me.ultraGrid1.EnforceXsdConstraints("..\simpleSchema.xsd")
End Sub
// simpleSchema.xsd
// ******************************************************************************
<xs:schema  targetNamespace="http://tempuri.org/simpleSchema.xsd"
			elementFormDefault="qualified"
			xmlns="http://tempuri.org/simpleSchema.xsd"			
			xmlns:xs="http://www.w3.org/2001/XMLSchema" 
			xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">			
    <xs:element name="MyDataSet" msdata:IsDataSet="true">
		<xs:complexType>
			<xs:choice maxOccurs="unbounded">
				<!-- Declares a table of data called "People" which must have between 1 and 5 rows of data. -->			
				<xs:element name="People" minOccurs="1" maxOccurs="5">
					<xs:complexType>
						<xs:sequence>						
							<!-- Declares a column called "Name" of type string where the 
							     length of the value must be at most 30 characters.  Setting 
							     'minOccurs' to 1 indicates that cells in this column cannot be empty/null. -->
							<xs:element name="Name" minOccurs="1">
								<xs:simpleType>
									<xs:restriction base="xs:string">
										<xs:maxLength value="30" />
									</xs:restriction>
								</xs:simpleType>
							</xs:element>
							
							<!-- Declares a DateTime column called "DateOfBirth". -->
							<xs:element name="DateOfBirth"  type="xs:dateTime" />							
						</xs:sequence>
						
						<!-- Declares a column called "IsFamous" which is represented in XML as an attribute. -->
						<xs:attribute name="IsFamous" type="xs:boolean" />						
					</xs:complexType> 
				</xs:element>
			</xs:choice>					
		</xs:complexType>				
    </xs:element>                         
</xs:schema>

// MyApp.cs
// ******************************************************************************
private void SetupGrid()
{
	// Create a DataSet and then read its structure in from the XSD schema file.
	//
	DataSet ds = new DataSet();
	ds.ReadXmlSchema( "..\\..\\simpleSchema.xsd" );

	// Get a reference to the "People" table.
	//
	DataTable tbl = ds.Tables["People"];

	// Add a few rows of data: People(IsFamous, Name, DateOfBirth)
	//
	tbl.Rows.Add( new object[]{ true,  "Ludwig Van Beethoven", new DateTime( 1770, 12, 17 ) } );
	tbl.Rows.Add( new object[]{ false, "Joe Nobody", new DateTime( 1972, 11,  2 ) } );
	tbl.Rows.Add( new object[]{ true,  "Pablo Picasso", new DateTime( 1881, 10, 25 ) } );

	// Bind the grid to the DataSet object.
	//
	this.ultraGrid1.DataSource = ds;

	// Allow for new rows to be added.
	//
	this.ultraGrid1.DisplayLayout.Override.AllowAddNew = AllowAddNew.TemplateOnBottom;

	// Inform the grid that it should enforce the constraints found in the XSD schema
	// which are not honored by the DataSet.
	//
	this.ultraGrid1.EnforceXsdConstraints( "..\\..\\simpleSchema.xsd" );
}
参照