XmlSchemaValidator.GetExpectedParticles XmlSchemaValidator.GetExpectedParticles XmlSchemaValidator.GetExpectedParticles XmlSchemaValidator.GetExpectedParticles Method

定義

現在の要素コンテキストで予期されるパーティクルを返します。Returns the expected particles in the current element context.

public:
 cli::array <System::Xml::Schema::XmlSchemaParticle ^> ^ GetExpectedParticles();
public System.Xml.Schema.XmlSchemaParticle[] GetExpectedParticles ();
member this.GetExpectedParticles : unit -> System.Xml.Schema.XmlSchemaParticle[]
Public Function GetExpectedParticles () As XmlSchemaParticle()

戻り値

XmlSchemaParticle オブジェクトの配列。または、予期されるパーティクルがない場合は空の配列。An array of XmlSchemaParticle objects or an empty array if there are no expected particles.

注釈

GetExpectedParticles メソッドが返せる有効なパーティクルは、XmlSchemaElement クラスと XmlSchemaAny クラスのインスタンスです。The valid particles that can be returned by the GetExpectedParticles method are instances of the XmlSchemaElement and XmlSchemaAny classes.

コンテンツ モデルのコンポジターが xs:sequence の場合、シーケンス中の次のパーティクルのみが返されます。When the compositor for the content model is an xs:sequence, only the next particle in the sequence is returned. コンテンツ モデルのコンポジターが xs:all または xs:choice の場合、現在の要素コンテキストに続くことができる有効なパーティクルすべてが返されます。If the compositor for the content model is an xs:all or an xs:choice, then all valid particles that could follow in the current element context are returned.

たとえば、XSD (XML スキーマ定義言語) スキーマと続く XML ドキュメントで、book 要素の検証後、book 要素は現在の要素コンテキストになります。For example, in the XML Schema Definition Language (XSD) schema and XML document that follow, after validating the book element, the book element is the current element context. GetExpectedParticles メソッドは、XmlSchemaElement 要素を表す単一の title オブジェクトを含む配列を返します。The GetExpectedParticles method returns an array containing a single XmlSchemaElement object representing the title element. 検証コンテキストが title 要素の場合、GetExpectedParticles メソッドは空の配列を返します。When the validation context is the title element, the GetExpectedParticles method returns an empty array. GetExpectedParticles メソッドが title 要素の検証後で description 要素の検証前に呼び出されると、このメソッドは XmlSchemaElement 要素を表す単一の description オブジェクトを含む配列を返します。If the GetExpectedParticles method is called after the title element has been validated but before the description element has been validated, it returns an array containing a single XmlSchemaElement object representing the description element. GetExpectedParticles メソッドが description 要素の検証後に呼び出されると、メソッドはワイルドカードを表す単一の XmlSchemaAny オブジェクトを含む配列を返します。If the GetExpectedParticles method is called after the description element has been validated then it returns an array containing a single XmlSchemaAny object representing the wildcard.

Dim reader As XmlReader =  XmlReader.Create("input.xml")   

Dim schemaSet As XmlSchemaSet =  New XmlSchemaSet()   
schemaSet.Add(Nothing, "schema.xsd")  
Dim manager As XmlNamespaceManager =  New XmlNamespaceManager(reader.NameTable)   

Dim validator As XmlSchemaValidator =  New XmlSchemaValidator(reader.NameTable,schemaSet,manager,XmlSchemaValidationFlags.None)  
validator.Initialize()  

validator.ValidateElement("book", "", Nothing)  
validator.GetUnspecifiedDefaultAttributes(New ArrayList())  
validator.ValidateEndOfAttributes(Nothing)  
For Each element As XmlSchemaElement In validator.GetExpectedParticles()  
    Console.WriteLine(element.Name)  
Next  

validator.ValidateElement("title", "", Nothing)  
validator.GetUnspecifiedDefaultAttributes(New ArrayList())  
validator.ValidateEndOfAttributes(Nothing)  
For Each element As XmlSchemaElement In validator.GetExpectedParticles()  
    Console.WriteLine(element.Name)  
Next  
validator.ValidateEndElement(Nothing)  

For Each element As XmlSchemaElement In validator.GetExpectedParticles()  
    Console.WriteLine(element.Name)  
Next  

validator.ValidateElement("description", "", Nothing)  
validator.GetUnspecifiedDefaultAttributes(New ArrayList())  
validator.ValidateEndOfAttributes(Nothing)  
validator.ValidateEndElement(Nothing)  

For Each particle As XmlSchemaParticle In validator.GetExpectedParticles()  
    Console.WriteLine(particle.GetType())  
Next  

validator.ValidateElement("namespace", "", Nothing)  
validator.GetUnspecifiedDefaultAttributes(New ArrayList())  
validator.ValidateEndOfAttributes(Nothing)  
validator.ValidateEndElement(Nothing)  

validator.ValidateEndElement(Nothing)  
XmlReader reader = XmlReader.Create("input.xml");  

XmlSchemaSet schemaSet = new XmlSchemaSet();  
schemaSet.Add(null, "schema.xsd");  
XmlNamespaceManager manager = new XmlNamespaceManager(reader.NameTable);  

XmlSchemaValidator validator = new XmlSchemaValidator(reader.NameTable, schemaSet, manager, XmlSchemaValidationFlags.None);  
validator.Initialize();  

validator.ValidateElement("book", "", null);  

validator.GetUnspecifiedDefaultAttributes(new ArrayList());  
validator.ValidateEndOfAttributes(null);  
foreach (XmlSchemaElement element in validator.GetExpectedParticles())  
{  
    Console.WriteLine(element.Name);  
}  

validator.ValidateElement("title", "", null);  
validator.GetUnspecifiedDefaultAttributes(new ArrayList());  
validator.ValidateEndOfAttributes(null);  
foreach (XmlSchemaElement element in validator.GetExpectedParticles())  
{  
    Console.WriteLine(element.Name);  
}  
validator.ValidateEndElement(null);  

foreach (XmlSchemaElement element in validator.GetExpectedParticles())  
{  
    Console.WriteLine(element.Name);  
}  

validator.ValidateElement("description", "", null);  
validator.GetUnspecifiedDefaultAttributes(new ArrayList());  
validator.ValidateEndOfAttributes(null);  
validator.ValidateEndElement(null);  

foreach (XmlSchemaParticle particle in validator.GetExpectedParticles())  
{  
    Console.WriteLine(particle.GetType());  
}  

validator.ValidateElement("namespace", "", null);  
validator.GetUnspecifiedDefaultAttributes(new ArrayList());  
validator.ValidateEndOfAttributes(null);  
validator.ValidateEndElement(null);  

validator.ValidateEndElement(null);  

この例は、次の XML を入力として使用します。The example takes the following XML as input.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="book">

<xs:complexType>

<xs:sequence>

<xs:element name="title" type="xs:string" />

<xs:element name="description" type="xs:string" />

<xs:any processContents ="lax"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

この例は、次の XSD スキーマを入力として使用します。The example takes the following XSD schema as input.

<book>

<title>My Book</title>

<description>My Book's Description</description>

<namespace>System.Xml.Schema</namespace>

</book>

適用対象

こちらもご覧ください