XMLNode.Validate Method (Word)
Validates an individual XML element against the XML schemas that are attached to a document.
Syntax
expression .Validate
expression An expression that returns an XMLNode object.
Return Value
Nothing
Remarks
Use the Validate method with the ValidationStatus and 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, Microsoft Word populates the XMLSchemaViolations property of the Document object with a collection of the XML nodes that have validation errors.
Example
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
objNode.Validate
If objNode.ValidationStatus <> wdXMLValidationStatusOK Then
strValid = strValid & objNode.BaseName & vbTab & _
objNode.ValidationErrorText & vbCrLf
End If
Next
MsgBox "The following elements do not validate against " & _
"the schema." & vbCrLf & vbCrLf & strValid & vbCrLf & _
"You should fix these elements before continuing."