Validate Method

Verifies an individual XML element or the entire document against the attached XML schema or schemas.


expression Required. An expression that returns one of the objects in the Applies To list.


Use the Validate method with the ValidationStatus and ****

Visit ValidationErrorText

properties to determine if an XML element is valid against 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, Word populates the XMLSchemaViolations collection with the XML nodes that have validation errors.


The following example checks each element and attribute in the active document and displays a message containing the elements and attributes that do not pass validation according to the schema and a description of why.

Dim objNode As XMLNode
Dim strValid As String
For Each objNode In ActiveDocument.XMLNodes
    If objNode.ValidationStatus <> wdXMLValidationStatusOK Then
        strValid = strValid & objNode.BaseName & vbTab & _
            objNode.ValidationErrorText & vbCrLf
    End If
MsgBox "The following elements do not validate against " & _
    "the schema." & vbCrLf & vbCrLf & strValid & vbCrLf & _
    "You should fix these elements before continuing."

Applies to | XMLNode Object | XMLSchemaReferences Collection