Share via


XMLNode.NodeType 屬性

取得表示 XMLNode 的種類,種類包含屬性與項目。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word (在 Microsoft.Office.Tools.Word.dll 中)

語法

'宣告
ReadOnly Property NodeType As WdXMLNodeType
    Get
WdXMLNodeType NodeType { get; }

屬性值

型別:Microsoft.Office.Interop.Word.WdXMLNodeType
表示節點型別的其中一個 WdXMLNodeType 值。

備註

NodeType 屬性可以是下列其中一個 WdXMLNodeType 值:

使用 NodeType 屬性來判斷您所使用的節點型別,所以您不會在節點上嘗試執行無效的作業。 例如,Attributes 屬性只會套用至項目節點,雖然此屬性出現在 XMLNode 控制項的可用屬性清單中。

範例

下列程式碼範例使用 NodeType 屬性判斷 XMLNode 是否為項目或屬性節點。 如果 XMLNode 為項目,範例會使用 NodeText 屬性來設定項目中的文字。 如果 XMLNode 為屬性,則範例會使用 NodeValue 屬性來設定屬性值。 此範例假設目前的文件包含名為 CustomerLastNameNode 的 XMLNode

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
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 + "'.");
    }
}

.NET Framework 安全性

請參閱

參考

XMLNode 介面

Microsoft.Office.Tools.Word 命名空間