Share via


XMLNode.NodeText 屬性

取得或設定 XMLNode 控制項的文字值。

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

語法

'宣告
Property NodeText As String
    Get
    Set
string NodeText { get; set; }

屬性值

型別:System.String
XMLNode 控制項的文字值。

備註

設定文字值不刪除在 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 命名空間