Class XMLNode (Word VBA)

The class XMLNode represents a single XML element applied to a document.

Class Document gives access to class XMLNode.


Dim xml as XMLNode
Set xml = Dim strXPath As String: strXPath = 
ActiveDocument.SelectSingleNode(XPath:=strXPath)

For Each

Here is an example of processing the XMLNode items in a collection.


Dim nod As XMLNode 
Dim strValid As String 
For Each nod In ActiveDocument.XMLNodes 
 nod.Validate 
 If nod.ValidationStatus <> wdXMLValidationStatusOK Then 
 strValid = strValid & nod.BaseName & vbTab & nod.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."

Methods

Copy - Copies the specified XML element, excluding XML markup, to the Clipboard.

Cut - Removes the specified XML element from the document and places it on the Clipboard.

Delete - Deletes the specified XML element from an XML document.

RemoveChild - Removes a child element from the specified element.

SelectNodes - Returns an XMLNodes collection that represents all the child elements that match the XPath parameter, in the order in which they appear within the specified XML element.

SelectSingleNode - Returns an XMLNode object that represents the first child element that matches the XPath parameter within the specified XML element.

SetValidationError - Changes the validation error text displayed to a user for a specified node and forces Word to report a node as invalid.

Validate - Validates an individual XML element against the XML schemas that are attached to a document.

Properties

BaseName (Default member) - Returns a String that represents the name of the element without any prefix.

Attributes returns an XMLNodes collection that represents the attributes for the specified element.

ChildNodes returns an XMLNodes collection that represents the child elements of a specified element.

FirstChild returns a DiagramNode object that represents the first child node of a parent node.

HasChildNodes returns a Boolean that represents whether an XML node has child nodes.

LastChild returns an XMLNode object that represents the last child node of an XML element.

Level returns a WdXMLNodeLevel constant that represents whether an XML element is part of a paragraph, is a paragraph, or is contained within a table cell or contains a table row.

NamespaceURI returns a String that represents the Uniform Resource Identifier (URI) of the schema namespace for the specified object.

NextSibling returns an XMLNode object that represents the next element in the document that is at the same level as the specified element.

NodeType returns a WdXMLNodeType constant that represents the type of node.

NodeValue returns or sets a String that represents the value of an XML element.

OwnerDocument returns a Document object that represents the parent document of the specified XML element.

ParentNode returns an XMLNode object that represents the parent element of the specified element.

PlaceholderText sets or returns a String that represents the text displayed for an element that contains no text.

PreviousSibling returns an XMLNode object that represents the previous element in the document that is at the same level as the specified element.

Range returns a Range object that represents the portion of a document that is contained in the specified object.

Text returns or sets the text contained within the XML element.

ValidationErrorText returns a String that represents the description for a validation error on an XMLNode object.

ValidationStatus returns a WdXMLValidationStatus constant that represents whether an element or attribute is valid according to the attached schema.

WordOpenXML returns a String that represents the XML for the node in the Microsoft Word Open XML format.

XML

Document - Represents a document. The Document object is a member of the Documents collection. The Documents collection contains all the Document objects that are currently open in Word.

Range - Represents a contiguous area in a document. Each Range object is defined by a starting and ending character position.

XMLNodes - A collection of XMLNode objects that represents the nodes in the tree view of the XML Structure task pane, which indicates the elements that a user has applied to a document. 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.Y