create xml value with vbscript

188 views Asked by At

i need to add the value of ExtraDataItem name="HostOnly/VirtualBox Host-Only Ethernet Adapter/IPAddress" value="192.168.2.1" to my xml.. In the picture you can see how it looks after it has been added by the program. In the default xml, only 2 lines exist in ExtraData.

Can you please tell me how to do it using Msxml2? i tried with this code, but no results :(

Set xmlDoc = CreateObject("Msxml2.DOMDocument")

xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.load(file1)

Set objNodeList = xmlDoc.getElementsByTagName("DHCPServers")

For each comNodeItem in objNodeList
    'JobName = comNodeItem.getAttribute("name")
    for each fileNodeItem in comNodeItem.ChildNodes
        fileName = fileNodeItem.getAttribute("IPAddress")
        fileNodeItem.setAttribute "IPAddress", "192.168.2.10"
        fileName = fileNodeItem.getAttribute("lowerIP")
        fileNodeItem.setAttribute "lowerIP", "192.168.2.2"
        fileName = fileNodeItem.getAttribute("upperIP")
        fileNodeItem.setAttribute "upperIP", "192.168.2.9"
    next
Next

Set objNodeList = xmlDoc.getElementsByTagName("ExtraData")

For each comNodeItem in objNodeList
    'JobName = comNodeItem.getAttribute("name")
    for each fileNodeItem in comNodeItem.ChildNodes
        fileName = fileNodeItem.getAttribute("ExtraDataItem name")
        comNodeItem.createAttribute "HostOnly/VirtualBox Host-Only Ethernet Adapter/IPAddress"
        fileName = fileNodeItem.getAttribute("value")
        fileNodeItem.setAttribute "value", "192.168.2.1"
    next
Next

xmlDoc.save(file1)

enter image description here

1

There are 1 answers

3
Ansgar Wiechers On

File says DO NOT EDIT THIS FILE.

If you need to programmatically modify the VirtualBox configuration, use the appropriate tools:

VBoxManage setextradata global "HostOnly/VirtualBox Host-Only Ethernet Adapter/IPAddress" "192.168.2.1"