NodeType Property

Microsoft Word Visual Basic

Show All Show All

NodeType Property

Returns a wdXMLNodeType constant that represents the type of node.

wdXMLNodeType can be one of the following wdXMLNodeType constants.

wdXMLNodeAttribute Indicates an attribute node.
wdXMLNodeElement Indicates an element node.

expression.NodeType

expression    Required. An expression that returns an XMLNode object.

Remarks

An XMLNode object can be either an XML element or an attribute of an element. Use the NodeType property to determine which type of node you are working with so that you don't attempt to perform invalid operations on the node. For example, the Attributes property applies only to element nodes, although it will appear in the list of available properties for the XMLNode object.

Example

The following example adds the author attribute to the book element in the active document and then sets the value of the attribute.

    Sub AddIDAttribute()
    Dim objElement As XMLNode
    Dim objAttribute As XMLNode

    For Each objElement In ActiveDocument.XMLNodes
        If objElement.NodeType = wdXMLNodeElement Then
            If objElement.BaseName = "book" Then
                
                Set objAttribute = objElement.Attributes _
                    .Add("author", objElement.NamespaceURI)

                objAttribute.NodeValue = "David Barber"
                
                Exit For
            End If
        End If
    Next
End Sub