XMLAttributesColl Object
Description
An object representing a collection of element attributes. This object can be accessed using the XMLElement.Attributes method.
Properties
![]() | Returns the number of attributes in the XML attributes collection. |
![]() | Returns the attribute found in the specified position within the XML attributes collection. |
![]() | Returns the attribute with the specified name. |
Count Property
Description
Returns the number of attributes in the XML attributes collection.
Syntax
XMLAttributesColl.Count
Return Value
Number
![Closed](../../Skins/Default/Stylesheets/Images/transparent.gif)
The following function uses the Count property to find the number of attributes in the root element and find and display all of them.
Set doc = XMLUtil.CreateXML()
doc.LoadFile "c:\example.xml"
Set root = doc.GetRootElement()
Set attribs = root.Attributes()
numOfAttr = attribs.Count()
i = 1
While i <= numOfAttr
Set attr = attribs.Item(i)
nameStr = attr.Name()
valStr = attr.Value()
attrStr = attrStr + nameStr+"="+chr(34)+valStr+chr(34) + " "
i = i+1
Wend
msgbox "Attributes: " + attrStr
Item Property
Description
Returns the attribute found in the specified position within the XML attributes collection.
Syntax
XMLAttributesColl.Item (Position)
Argument | Type | Description |
---|---|---|
Position | Number | The location of the attribute to return. |
Return Value
![Closed](../../Skins/Default/Stylesheets/Images/transparent.gif)
The following function uses the Item property to enumerate the attributes to print all the attributes of the root element.
Set doc = XMLUtil.CreateXML()
doc.LoadFile "c:\example.xml"
Set root = doc.GetRootElement()
Set attribs = root.Attributes()
numOfAttr = attribs.Count()
i = 1
While i <= numOfAttr
Set attr = attribs.Item(i)
nameStr = attr.Name()
valStr = attr.Value()
attrStr = attrStr + nameStr+"="+chr(34)+valStr+chr(34) + " "
i = i+1
Wend
msgbox "Attributes: " + attrStr
ItemByName Property
Description
Returns the attribute with the specified name.
Syntax
XMLAttributesColl.ItemByName (AttributeName )
Return Value
![Closed](../../Skins/Default/Stylesheets/Images/transparent.gif)
The following example uses the ItemByName property to confirm that the UFT One attribute was added.
Set doc = XMLUtil.CreateXML()
doc.LoadFile "c:\example.xml"
Set root = doc.GetRootElement()
Set attrs = root.Attributes()
msg = "At first I had " & attrs.Count() & " attributes. "
root.AddAttribute "UFT One","Great"
Set attr = attrs.ItemByName("UFT One")
if attr is nothing then
msgbox "Failed to add attribute!!!"
end if
msg = msg + "Now I have " & attrs.Count() & " attributes. "
root.RemoveAttribute "UFT One"
msg = msg + "Again I have " & attrs.Count() & " attributes."
msgbox msg