WPS 加载项开发 > 文字 API 参考 > XMLNode > 属性 > XMLNode.Attributes 属性
返回一个 XMLNodes 集合,该集合代表指定元素的属性。

语法

表达式.Attributes

表达式   必选。一个代表 XMLNode 对象的变量。

说明

使用 Attributes 属性返回的 XMLNodes 集合中的所有 XMLNode 对象的 NodeType 属性值均为 wdXMLNodeAttribute

示例

以下示例将 author 属性添加到活动文档中的 book 元素,然后设置该属性的值。

示例代码
function AddIDAttribute(){
    let objElement = ActiveDocument.XMLNodes
    for(let i = 1; i <= objElement.Count; i++){
        if(objElement.Item(i).NodeType == wdXMLNodeElement){
            if(objElement.Item(i).BaseName == "book"){
                
                let objAttribute = objElement.Item(i).Attributes.Add("author", objElement.NamespaceURI)
                objAttribute.NodeValue = "David Barber"
                
            }
        }
    }
}


请参阅