XMLAttribute Object
Description
An object representing an XML element attribute. This object can be accessed using one of the following methods:
Properties
Name | Returns the attribute's name. |
Namespace | Returns the attribute's namespace. |
Prefix | Returns the prefix (name) of the attribute's namespace. |
Value | Returns the attribute's value. |
Name Property
Description
Returns the attribute's name.
Syntax
XMLAttribute.Name
Return Value
String
The following function uses the Name property to find the names of each of the attributes in the root element and display them together with their values.
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
Namespace Property
Description
Returns the attribute's namespace.
Syntax
XMLAttribute.Namespace
Return Value
String
The following example uses the Namespace property to find and print the value of the Attr1 attribute's namespace.
XmlString = "<Root xmlns:myNameSpace = ""http://company.com"" myNameSpace:Attr1=""Attr1"“></Root>"
Set oXmlDoc = XMLUtil.CreateXML
oXmlDoc.Load XmlString
print oXmlDoc.ToString
print oXmlDoc.GetRootElement.Attributes.Item(2).Namespace ' will print "http://company.com
Prefix Property
Description
Returns the prefix (name) of the attribute's namespace.
Syntax
XMLAttribute.Prefix
Return Value
String
The following example uses the Prefix property to find and print the value of the Attr1 attribute's prefix.
XmlString = "<Root xmlns:myNameSpace = ""http://company.com"" myNameSpace:Attr1=""Attr1""></Root>" Set oXmlDoc = XMLUtil.CreateXML oXmlDoc.Load XmlString print oXmlDoc.ToString print oXmlDoc.GetRootElement.Attributes.Item(2).Prefix ' will print myNameSpace
Value Property
Description
Returns the attribute's value.
Syntax
XMLAttribute.Value
Return Value
String
The following function uses the Value property to find the values of the attributes in the root element and display them together with their attribute names.
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