Editare

Partajați prin


XmlSchemaValidator.GetExpectedParticles Method

Definition

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()

Returns

An array of XmlSchemaParticle objects or an empty array if there are no expected particles.

Remarks

The valid particles that can be returned by the GetExpectedParticles method are instances of the XmlSchemaElement and XmlSchemaAny classes.

When the compositor for the content model is an xs:sequence, only the next particle in the sequence is returned. 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.

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. The GetExpectedParticles method returns an array containing a single XmlSchemaElement object representing the title element. When the validation context is the title element, the GetExpectedParticles method returns an empty array. 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. 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);  

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>

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>

Applies to

See also