Share via


XMLNode.Attributes 屬性

取得 Microsoft.Office.Interop.Word.XMLNodes 集合,表示 XMLNode 控制項的屬性。

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

語法

'宣告
ReadOnly Property Attributes As XMLNodes
    Get
XMLNodes Attributes { get; }

屬性值

型別:Microsoft.Office.Interop.Word.XMLNodes
Microsoft.Office.Interop.Word.XMLNodes 集合表示 XMLNode 控制項的屬性。

備註

藉由使用 Attributes 屬性所傳回在 Microsoft.Office.Interop.Word.XMLNodes 集合中的所有 Microsoft.Office.Interop.Word.XMLNode 控制項,都擁有 wdXMLNodeAttributeXMLNode.NodeType 屬性值。

範例

下列程式碼範例使用 Attributes 屬性 (Property) 將屬性 (Attribute) 加入至 XMLNode 控制項。 NamespaceURI 屬性會用來指定結構描述命名空間。 然後範例會逐一查看 XMLNode 中的每個屬性,並且顯示屬性名稱和值。 XMLNode 的名稱可從 BaseName 屬性中取得。 這個範例假設目前的文件有包含名為 CustomerNode 的 XMLNode,前者擁有在結構描述中宣告的 NewCustomer 屬性。

Private Sub DisplayAttributes()
    Dim newAttribute As Word.XMLNode = _
        Me.CustomerNode.Attributes.Add("NewCustomer", _
        Me.CustomerNode.NamespaceURI)
    newAttribute.NodeValue = "yes"

    Dim attribute1 As Word.XMLNode
    For Each attribute1 In Me.CustomerNode.Attributes
        MsgBox("'" & Me.CustomerNode.BaseName & _
            "' has the attribute '" & attribute1.BaseName & _
            "' with the value '" & attribute1.NodeValue & "'.")
    Next attribute1
End Sub
private void DisplayAttributes()
{
    Word.XMLNode newAttribute = 
        this.CustomerNode.Attributes.Add("NewCustomer",
        this.CustomerNode.NamespaceURI, ref missing);
    newAttribute.NodeValue = "yes";

    foreach (Word.XMLNode attribute1 in this.CustomerNode.Attributes)
    {
        MessageBox.Show("'" + this.CustomerNode.BaseName +
            "' has the attribute '" + attribute1.BaseName +
            "' with the value '" + attribute1.NodeValue +
            "'.");
    }
}

.NET Framework 安全性

請參閱

參考

XMLNode 介面

Microsoft.Office.Tools.Word 命名空間