Share via


XMLNode.NodeValue 屬性

取得或設定表示屬性的 XMLNode 值。

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

語法

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

屬性值

型別:System.String
表示 XMLNode 的屬性值。

備註

使用 NodeType 屬性來判斷您所使用的節點型別。

因為具有 wdXMLNodeElementNodeType 值的 XMLNode 控制項,所以 NodeValue 屬性不會有任何回傳。

範例

下列程式碼範例使用 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 命名空間