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 don't 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 don't validate against " & _ 
 "the schema." & vbCrLf & vbCrLf & strValid & vbCrLf & _ 
 "You should fix these elements before continuing."

See also

XMLNode Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.