针对附加到文档的 XML 架构验证单个 XML 元素。
语法
expression。 Validate
表达 返回 XMLNode 对象的表达式。
返回值
Nothing
注解
使用 Validate 方法与 ValidationStatus 和 ValidationErrorText 属性确定 XML 元素是否有效对应用的架构,并向用户显示的错误文本。 使用 SetValidationError 方法来重写自定义验证错误的架构冲突。
运行 验证 方法时,Microsoft Word 将填充 文档 对象的 XMLSchemaViolations 属性,具有验证错误的 XML 节点的集合。
示例
以下示例检查活动文档中的每个元素和属性,并显示一条消息,其中包含未根据架构通过验证的元素和属性,并说明原因。
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."
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。