XMLNode.Validate Method
Validates an individual XMLNode control against the attached XML schema or schemas.
Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)
Syntax
'Declaration
Sub Validate
void Validate()
Remarks
Use the Validate method with the ValidationStatus and ValidationErrorText properties to determine whether an XML element is valid according to the applied schema and what error text to display to the user. Use the SetValidationError method to override the schema violations with custom validation errors.
When you run the Validate method, Microsoft Office Word populates the XMLSchemaViolations collection with the XML nodes that have validation errors.
Examples
The following code example sets the text value of an XMLNode and validates the node by using the Validate method. The example then uses the ValidationStatus property to determine whether the node validated. If the node did not validate, then the example uses the ValidationErrorText property to display the validation error message. This example assumes that the current document contains an XMLNode named CustomerAddress1Node. If CustomerAddress1Node maps to a schema element that has an integer data type, then the validation will fail.
Private Sub ValidateNode()
Me.CustomerAddress1Node.NodeText = "Nineteen Hundred"
Me.CustomerAddress1Node.Validate()
If Me.CustomerAddress1Node.ValidationStatus = _
Word.WdXMLValidationStatus.wdXMLValidationStatusOK Then
MsgBox("'" & Me.CustomerAddress1Node.BaseName & "' validates.")
Else
MsgBox("'" & Me.CustomerAddress1Node.BaseName & _
"': " & Me.CustomerAddress1Node.ValidationErrorText(False))
End If
End Sub
private void ValidateNode()
{
this.CustomerAddress1Node.NodeText = "Nineteen Hundred";
this.CustomerAddress1Node.Validate();
if (this.CustomerAddress1Node.ValidationStatus ==
Word.WdXMLValidationStatus.wdXMLValidationStatusOK)
{
MessageBox.Show("'" + this.CustomerAddress1Node.BaseName +
"' validates.");
}
else
{
MessageBox.Show("'" + this.CustomerAddress1Node.BaseName +
"': " + this.CustomerAddress1Node.ValidationErrorText[false]);
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.