XmlSchemaObject クラス
空のスキーマを作成します。
この型のすべてのメンバの一覧については、XmlSchemaObject メンバ を参照してください。
System.Object
System.Xml.Schema.XmlSchemaObject
派生クラス
MustInherit Public Class XmlSchemaObject
[C#]
public abstract class XmlSchemaObject
[C++]
public __gc __abstract class XmlSchemaObject
[JScript]
public abstract class XmlSchemaObject
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
使用例
[Visual Basic, C#, C++] 各スキーマ オブジェクトを表示する例を次に示します。
Option Strict
Option Explicit
Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class ValidXSD
Public Shared Sub Main()
Dim xsd As String = "example.xsd"
Dim fs As FileStream
Dim schema As XmlSchema
Try
fs = New FileStream(xsd, FileMode.Open)
schema = XmlSchema.Read(fs,new ValidationEventHandler(AddressOf ShowCompileError))
schema.Compile(AddressOf ShowCompileError)
If schema.IsCompiled Then
DisplayObjects(schema)
End If
Catch e As XmlSchemaException
Console.WriteLine("LineNumber = {0}", e.LineNumber)
Console.WriteLine("LinePosition = {0}", e.LinePosition)
Console.WriteLine("Message = {0}", e.Message)
Console.WriteLine("Source = {0}", e.Source)
End Try
End Sub 'Main
Overloads Private Shared Sub DisplayObjects(o As Object)
DisplayObjects(o, "")
End Sub 'DisplayObjects
Overloads Private Shared Sub DisplayObjects(o As Object, indent As String)
Console.WriteLine("{0}{1}", indent, o)
Dim property1 As PropertyInfo
For Each property1 In o.GetType().GetProperties()
If property1.PropertyType.FullName = "System.Xml.Schema.XmlSchemaObjectCollection" Then
Dim childObjectCollection As XmlSchemaObjectCollection = CType(property1.GetValue(o, Nothing), XmlSchemaObjectCollection)
Dim schemaObject As XmlSchemaObject
For Each schemaObject In childObjectCollection
DisplayObjects(schemaObject, indent + ControlChars.Tab)
Next schemaObject
End If
Next property1
End Sub 'DisplayObjects
Private Shared Sub ShowCompileError(sender As Object, e As ValidationEventArgs)
Console.WriteLine("Validation Error: {0}", e.Message)
End Sub 'ShowCompileError
End Class 'ValidXSD
[C#]
using System;
using System.Xml;
using System.Xml.Schema;
using System.IO;
using System.Reflection;
public class ValidXSD {
public static int Main() {
string xsd = "example.xsd";
FileStream fs;
XmlSchema schema;
try {
fs = new FileStream(xsd, FileMode.Open);
schema = XmlSchema.Read(fs, new ValidationEventHandler(ShowCompileError));
schema.Compile(new ValidationEventHandler(ShowCompileError));
if (schema.IsCompiled) {
DisplayObjects(schema);
}
return 0;
} catch (XmlSchemaException e) {
Console.WriteLine("LineNumber = {0}", e.LineNumber);
Console.WriteLine("LinePosition = {0}", e.LinePosition);
Console.WriteLine("Message = {0}", e.Message);
Console.WriteLine("Source = {0}", e.Source);
return -1;
}
}
private static void DisplayObjects(object o) {
DisplayObjects(o, "");
}
private static void DisplayObjects(object o, string indent) {
Console.WriteLine("{0}{1}", indent, o);
foreach (PropertyInfo property in o.GetType().GetProperties()) {
if (property.PropertyType.FullName == "System.Xml.Schema.XmlSchemaObjectCollection") {
XmlSchemaObjectCollection childObjectCollection = (XmlSchemaObjectCollection) property.GetValue(o, null);
foreach (XmlSchemaObject schemaObject in childObjectCollection) {
DisplayObjects(schemaObject, indent + "\t");
}
}
}
}
private static void ShowCompileError(object sender, ValidationEventArgs e) {
Console.WriteLine("Validation Error: {0}", e.Message);
}
}
[C++]
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::IO;
using namespace System::Reflection;
public __gc class ValidXSD {
public:
static int main() {
String* xsd = S"example.xsd";
FileStream* fs;
XmlSchema* schema;
try {
fs = new FileStream(xsd, FileMode::Open);
schema = XmlSchema::Read(fs, new ValidationEventHandler(0, ShowCompileError));
schema->Compile(new ValidationEventHandler(0, ShowCompileError));
if (schema->IsCompiled) {
DisplayObjects(schema);
}
return 0;
} catch (XmlSchemaException* e) {
Console::WriteLine(S"LineNumber = {0}", __box(e->LineNumber));
Console::WriteLine(S"LinePosition = {0}", __box(e->LinePosition));
Console::WriteLine(S"Message = {0}",e->Message);
Console::WriteLine(S"Source = {0}",e->Source);
return -1;
}
}
private:
static void DisplayObjects(Object* o) {
DisplayObjects(o, S"");
}
static void DisplayObjects(Object* o, String* indent) {
Console::WriteLine(S"{0}{1}",indent,o);
System::Collections::IEnumerator* myEnum = o->GetType()->GetProperties()->GetEnumerator();
while (myEnum->MoveNext())
{
PropertyInfo* property = __try_cast<PropertyInfo*>(myEnum->Current);
if (property->PropertyType->FullName->Equals(S"System.Xml.Schema.XmlSchemaObjectCollection")) {
XmlSchemaObjectCollection* childObjectCollection = dynamic_cast<XmlSchemaObjectCollection*> (property->GetValue(o, 0));
System::Collections::IEnumerator* myEnum1 = childObjectCollection->GetEnumerator();
while (myEnum1->MoveNext())
{
XmlSchemaObject* schemaObject = __try_cast<XmlSchemaObject*>(myEnum1->Current);
DisplayObjects(schemaObject, String::Concat( indent, S"\t" ));
}
}
}
}
static void ShowCompileError(Object* /*sender*/, ValidationEventArgs* e) {
Console::WriteLine(S"Validation Error: {0}",e->Message);
}
};
int main()
{
ValidXSD::main();
}
[Visual Basic, C#, C++] この例では、入力として、 example.xsd というファイルを使用しています。
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:group name="testGroup">
<xs:choice>
<xs:any namespace="##any"/>
</xs:choice>
</xs:group>
<xs:element name="myElement" >
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:group ref="testGroup" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Xml.Schema
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
アセンブリ: System.Xml (System.Xml.dll 内)