System.Xml 2.0.0.0 4.0.0.0 System.Object

The class provides an efficient, high-performance mechanism to validate XML data against XML schemas in a push-based manner. For example, the class allows you to validate an XML infoset in-place without having to serialize it as an XML document and then reparse the document using a validating XML reader. The class can also be used to build validation engines over custom XML data sources or as a way to build a validating XML writer.

For more information about the class, see the XmlSchemaValidator Push-Based Validation topic.

The and validation flags of an object are not set be default. Additionally, the property of an object is null by default. As a result, external schemas referenced in include, imports, or redefine elements are not resolved by default.

Represents an XML Schema Definition Language (XSD) Schema validation engine. The class cannot be inherited.

- Constructor
  2.0.0.0
  4.0.0.0

  The following are important notes to consider when using the constructor.

  The contents of the parameter are copied into an internal object when the or the validation options are set. As a result, changes to the input object during validation do not affect the outcome of validation.

  If the parameter specified is not compiled, its method is called.

  The parameter is especially important for validating xs:QName types. The class does not copy the in-scope namespaces from the object but instead holds a reference to it. This allows new namespaces to be added to the object during the validation process.

  The and validation flags of an object are not set be default. Additionally, the property of an object is null by default. As a result, external schemas referenced in include, imports, or redefine elements are not resolved by default.

  Initializes a new instance of the class.

  An object containing element and attribute names as atomized strings.
  An object containing the XML Schema Definition Language (XSD) schemas used for validation.
  An object used for resolving namespaces encountered during validation.
  An value specifying schema validation options.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  The following are important notes to consider when using the method.

  The method can be used to simulate the effect of encountering an inline XML schema in the XML document being validated.

  The target namespace of the parameter cannot match that of any element or attribute already encountered by the object.

  If the validation option is not set, the method does nothing.

  Adds an XML Schema Definition Language (XSD) schema to the set of schemas used for validation.

  An object to add to the set of schemas used for validation.
- Method
  2.0.0.0
  4.0.0.0
  System.Void

  The method ends validation and checks identity constraints for the entire XML document if the validation option is set.

  Ends validation and checks identity constraints for the entire XML document.

- Method
  2.0.0.0
  4.0.0.0
  System.Xml.Schema.XmlSchemaAttribute[]

  The following are important notes to consider when using the method.

  If the method is called immediately after the method, all the attributes that could appear in the XML document are returned.

  If the method is called after one or more calls to the method, the attributes that haven't yet been validated for the current element are returned.

  Returns the expected attributes for the current element context.

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

- Method
  2.0.0.0
  4.0.0.0
  System.Xml.Schema.XmlSchemaParticle[]

  The valid particles that can be returned by the method are instances of the and 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 method returns an array containing a single object representing the title element. When the validation context is the title element, the method returns an empty array. If the 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 object representing the description element. If the method is called after the description element has been validated then it returns an array containing a single 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>

  Returns the expected particles in the current element context.

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

- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  The method must be called after validating all the attributes for the current element with the method. The method should be used to determine what default attributes are to be inserted into the XML document being validated.

  Validates identity constraints on the default attributes and populates the specified with objects for any attributes with default values that have not been previously validated using the method in the element context.

  An to populate with objects for any attributes not yet encountered during validation in the element context.
- Method
  2.0.0.0
  4.0.0.0
  System.Void

  The method is only valid if called immediately after the construction of an object or after a call to .

  Initializes the state of the object.

- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  The method that takes an as a parameter initializes an object to its starting state for partial validation.

  Initializes the state of the object using the specified for partial validation.

  An , , or object used to initialize the validation context of the object for partial validation.
- Property
  2.0.0.0
  4.0.0.0
  System.Xml.IXmlLineInfo To be added.

  Line information is reported by any thrown during the validation process.

  The default object returned by the property returns 0 for the and properties.

  Gets or sets the line number information for the XML node being validated.

- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  The following are important notes to consider when using the method.

  The method skips validation of the current element content and prepares the object to validate content in the parent element's context; it is equivalent to skipping validation for all the children of the current element and then calling the method.

  If the current element content is successfully skipped, the object's (if specified) property is set to .

  No validation errors are reported on skipped content.

  Skips validation of the current element content and prepares the object to validate content in the parent element's context.

  An object whose properties are set if the current element content is successfully skipped. This parameter can be null.
- Property
  2.0.0.0
  4.0.0.0
  System.Uri To be added.

  The source URI is reported by any thrown during the validation process.

  If the property is not set, the file name for the XML document is in validation error messages.

  Gets or sets the source URI for the XML node being validated.

- Method
  2.0.0.0
  4.0.0.0
  System.Object `` `` `` ``

  The following are important notes to consider when using the method.

  The method must be called after validating all the attributes for the current element with the method.

  If an object was passed to the method, the method validates the attribute against the object.

  If the attribute is successfully validated in the current element context, the object's (if specified) , , , and properties are set with the results of the validation.

  Validates the attribute name, namespace URI, and value in the current element context.

  The validated attribute's value.

  The local name of the attribute to validate. The namespace URI of the attribute to validate. The value of the attribute to validate. An object whose properties are set on successful validation of the attribute. This parameter can be null.
- Method
  2.0.0.0
  4.0.0.0
  System.Object `` `` `` ``

  The following are important notes to consider when using the method.

  The method must be called after validating all the attributes for the current element with the method.

  If an object was passed to the method, the method validates the attribute against the object.

  If the attribute is successfully validated in the current element context, the object's (if specified) , , , and properties are set with the results of the validation.

  Validates the attribute name, namespace URI, and value in the current element context.

  The validated attribute's value.

  The local name of the attribute to validate. The namespace URI of the attribute to validate. An delegate used to pass the attribute's value as a Common Language Runtime (CLR) type compatible with the XML Schema Definition Language (XSD) type of the attribute. An object whose properties are set on successful validation of the attribute. This parameter and can be null.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` ``

  The following are important notes to consider when using the method.

  If the element name is successfully validated in the current context, the object's (if specified) , , , and properties are set with the results of the validation.

  If the element name or any of its attributes are invalid the current context, the property is set to ; otherwise the property is set to .

  Validates the element in the current context.

  The local name of the element to validate. The namespace URI of the element to validate. An object whose properties are set on successful validation of the element's name. This parameter can be null.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` `` `` `` ``

  The following are important notes to consider when using the method.

  If the element name is successfully validated in the current context, the object's (if specified) , , , and properties are set with the results of the validation.

  If the element name or any of its attributes are invalid in the current context, the property is set to ; otherwise the property is set to .

  If the value was not passed as a parameter to the constructor, xsi:SchemaLocation and xsi:NoNamespaceSchemaLocation attribute values are ignored.

  Validates the element in the current context with the xsi:Type, xsi:Nil, xsi:SchemaLocation, and xsi:NoNamespaceSchemaLocation attribute values specified.

  The local name of the element to validate. The namespace URI of the element to validate. An object whose properties are set on successful validation of the element's name. This parameter can be null. The xsi:Type attribute value of the element. This parameter can be null. The xsi:Nil attribute value of the element. This parameter can be null. The xsi:SchemaLocation attribute value of the element. This parameter can be null. The xsi:NoNamespaceSchemaLocation attribute value of the element. This parameter can be null.
- Method
  2.0.0.0
  4.0.0.0
  System.Object ``

  The following are important notes to consider when using the method.

  For elements with simple content, the method verifies that the text content of the element is valid according to its data type and returns the parsed typed value. The text content of the element is obtained from the results of previous calls to .

  For elements with complex content, the method verifies if the content of the current element is complete.

  If the element has a default value, the value returned from the method is the default value for the element.

  If the object was constructed with the value as a parameter, the method checks the identity constraint rules (if any) that apply to the element.

  If the element is successfully validated in the current context, the object's (if specified) , , and properties are set with the results of the validation.

  Verifies if the text content of the element is valid according to its data type for elements with simple content, and verifies if the content of the current element is complete for elements with complex content.

  The parsed, typed text value of the element if the element has simple content.

  An object whose properties are set on successful validation of the element. This parameter can be null.
- Method
  2.0.0.0
  4.0.0.0
  System.Object `` ``

  If you are validating against the xs:key, xs:keyref, or xs:unique identity constraints, do not use the method overload. Instead, call the method and pass it the value of the element. Then call the method overload, which takes as an argument, to verify that the text content of the element is valid according to its data type.

  The following are important notes to consider when using the method.

  For elements with simple content, the method verifies that the text content of the element is valid according to its data type and returns the parsed typed value. The text content of the element is obtained from the typed content passed as a parameter.

  If calls to the method have been previously made, an is thrown.

  If the element has complex content an is thrown.

  If the object was constructed with the value as a parameter, the method checks the identity constraint rules (if any) that apply to the element.

  If the element is successfully validated in the current context, the object's (if specified) , , and properties are set with the results of the validation.

  Verifies if the text content of the element specified is valid according to its data type.

  The parsed, typed simple content of the element.

  An object whose properties are set on successful validation of the text content of the element. This parameter can be null. The typed text content of the element.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  The following are important notes to consider when using the method.

  The method should always be called before .

  The method must be called before proceeding with validation of an element's content.

  If all the required attributes in the element context are present, the object's (if specified) property is set to .

  Verifies whether all the required attributes in the element context are present and prepares the object to validate the child content of the element.

  An object whose properties are set on successful verification that all the required attributes in the element context are present. This parameter can be null.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  The following are important notes to consider when using the method.

  If the element has simple content, the text string specified is concatenated on each call to the method until the method is called. When the method is called, all the text is validated.

  If the element has complex content, no text concatenation occurs.

  Validates whether the text string specified is allowed in the current element context, and accumulates the text for validation if the current element has simple content.

  A text string to validate in the current element context.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  The following are important notes to consider when using the method.

  If the element has simple content, the text string specified is concatenated on each call to the method until the method is called. When the method is called, all the text is validated.

  If the element has complex content, no text concatenation occurs.

  Validates whether the text returned by the object specified is allowed in the current element context, and accumulates the text for validation if the current element has simple content.

  An delegate used to pass the text value as a Common Language Runtime (CLR) type compatible with the XML Schema Definition Language (XSD) type of the attribute.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` To be added.

  Validates whether the white space in the string specified is allowed in the current element context, and accumulates the white space for validation if the current element has simple content.

  A white space string to validate in the current element context.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` To be added.

  Validates whether the white space returned by the object specified is allowed in the current element context, and accumulates the white space for validation if the current element has simple content.

  An delegate used to pass the white space value as a Common Language Runtime (CLR) type compatible with the XML Schema Definition Language (XSD) type of the attribute.
- Event
  2.0.0.0
  4.0.0.0
  System.Xml.Schema.ValidationEventHandler

  If no is specified, an is thrown for all schema validation errors with an value of . An is not thrown for validation warnings with an value of .

  The that receives schema validation warnings and errors encountered during schema validation.

- Property
  2.0.0.0
  4.0.0.0
  System.Object To be added. To be added.

  Gets or sets the object sent as the sender object of a validation event.

- Property
  2.0.0.0
  4.0.0.0
  System.Xml.XmlResolver To be added.

  The and validation flags of an object are not set be default. Additionally, the property of an object is null by default. As a result, external schemas referenced in include, imports, or redefine elements are not resolved by default.

  Sets the object used to resolve xs:import and xs:include elements as well as xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes.