XMLNode 对象 (Word)XMLNode object (Word)

表示应用于文档的单个 XML 元素。Represents a single XML element applied to a document.


已应用于文档的每个 XML 元素都显示为 " xml 结构" 任务窗格中的树视图控件中的一个节点。Each XML element that has been applied to a document is displayed as a node in a tree view control in the XML Structure task pane. 树视图中的每个节点都是 XMLNode 对象的一个实例。Each node in the tree view is an instance of an XMLNode object. 树视图的层次结构表明节点是否包含子节点。The hierarchy in the tree view indicates whether a node contains child nodes.

使用XMLNodes集合的Item方法可返回单个XMLNode对象。Use the Item method of the XMLNodes collection to return an individual XMLNode object. 使用 Validate 方法验证 XML 元素有效根据所应用的架构和必需的子元素存在,以及按要求的顺序。Use the Validate method to verify that an XML element is valid according to the applied schemas and that any required child elements exist and are in the required order. 运行 Validate 方法后,使用 ValidationStatus 属性可验证元素是否有效,使用 ValidationErrorText 属性可显示关于如下内容的信息:用户应采用哪些措施来确保文档符合该 XML 架构的规则。Once you run the Validate method, use the ValidationStatus property to verify whether an element is valid, and use the ValidationErrorText property to display information about what the user needs to do to make the document conform to the XML schema rules.

以下示例验证活动文档中的每个 XML 元素。The following example validates each of the XML elements in the active document. 如果根据架构发现元素无效,则该示例向用户返回一条消息解释问题所在。If the element is found to be invalid against the schema, the example returns a message to the user explaining what the problem is.

Sub ValidateXMLElements() 
 Dim objNode As XMLNode 
 For Each objNode In ActiveDocument.XMLNodes 
 If objNode.ValidationStatus <> wdXMLValidationStatusOK Then 
 MsgBox objNode.ValidationErrorText(True) 
 End If 
End Sub

另请参阅See also

Word 对象模型参考Word Object Model Reference

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.