In the following example, we load the 'vocabulary.xml' file and call the setAttribute
method to alter the 'level' attribute of the first 'Word' element to '2'. The code then displays
the values of all the attributes.
XML:
<Vocabulary>
<Word type="noun" level="1">
<English>house</English>
<French>maison</French>
<Spanish>casa</Spanish>
</Word>
<Word type="verb" level="1">
<English>go</English>
<French>aller</French>
<Spanish>ir</Spanish>
</Word>
</Vocabulary>
Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("vocabulary.xml")
Set Elem = objXMLDoc.documentElement.firstChild
Elem.setAttribute "level", "2"
Set NamedNodeMap = Elem.attributes
For Each Attr In NamedNodeMap
document.write(Attr.value & "<br>")
Next
Output:
noun
2