Compartilhar via


XMLNode.NodeType Property

Definition

Gets a value that indicates whether an XMLNode is an attribute or an element.

public:
 property Microsoft::Office::Interop::Word::WdXMLNodeType NodeType { Microsoft::Office::Interop::Word::WdXMLNodeType get(); };
public Microsoft.Office.Interop.Word.WdXMLNodeType NodeType { get; }
member this.NodeType : Microsoft.Office.Interop.Word.WdXMLNodeType
Public ReadOnly Property NodeType As WdXMLNodeType

Property Value

One of the WdXMLNodeType values that represents the type of node.

Examples

The following code example uses the NodeType property to determine whether an XMLNode is an element or attribute node. If the XMLNode is an element, the example uses the NodeText property to set the text in the element. If the XMLNode is an attribute, the example uses the NodeValue property to set the attribute value. This example assumes that the current document contains an XMLNode named CustomerLastNameNode.

private void DisplayNodeDetails()
{
    if (this.CustomerLastNameNode.NodeType ==
        Word.WdXMLNodeType.wdXMLNodeElement)
    {
        this.CustomerLastNameNode.NodeText = "Smith";
        MessageBox.Show("The element '" +
            this.CustomerLastNameNode.BaseName + "' has the text '" + 
            this.CustomerLastNameNode.NodeText + "'.");
    }

    else if (this.CustomerLastNameNode.NodeType ==
        Word.WdXMLNodeType.wdXMLNodeAttribute)
    {
        this.CustomerLastNameNode.NodeValue = "Smith";
        MessageBox.Show("The attribute '" +
            this.CustomerLastNameNode.BaseName + "' has the value '" + 
           this.CustomerLastNameNode.NodeValue + "'.");
    }
}
Private Sub DisplayNodeDetails()
    If Me.CustomerLastNameNode.NodeType = _
        Word.WdXMLNodeType.wdXMLNodeElement Then
        Me.CustomerLastNameNode.NodeText = "Smith"
        MsgBox("The element '" & Me.CustomerLastNameNode.BaseName & _
            "' has the text '" & Me.CustomerLastNameNode.NodeText & "'.")

    ElseIf Me.CustomerLastNameNode.NodeType = _
        Word.WdXMLNodeType.wdXMLNodeAttribute Then
        Me.CustomerLastNameNode.NodeValue = "Smith"
        MsgBox("The attribute '" & Me.CustomerLastNameNode.BaseName & _
            "' has the value '" & Me.CustomerLastNameNode.NodeValue & "'.")
    End If
End Sub

Remarks

The NodeType property can be one of the following WdXMLNodeType values:

Use the NodeType property to determine which type of node you are working with so that you do not attempt to perform invalid operations on the node. For example, the Attributes property applies only to element nodes, although it appears in the list of available properties for the XMLNode control.

Applies to