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
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 属性向 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 命名空间