VBscript to edit xml file -
need using vbscript edit single xml file. i've found many examples edit xml values , i've frankensteined them edit xml file, have not been successful.
my xml file looks this:
<?xml version="1.0" encoding="utf-8" ?> - <configuration> <add key="kiosk_identifier" value="pc1" /> <add key="kiosk_gui_skin" value="fla" /> </configuration> i script go in , edit value "pc1" variable entered user in input box. bastardized code looks follows.
set xmldoc = _ createobject("microsoft.xmldom") xmldoc.async = "false" xmldoc.load("c:\scripts\configuration.xml") set colnodes=xmldoc.selectnodes _ ("//configuration['@add key'='pc1']") strname = inputbox("enter hostname:", "hostname config", "hostname") each objnode in colnodes objnode.text = strname next xmldoc.save "c:\scripts\configuration.xml"
if have 1 node attribute "value" = pc1 try this
set colnode = xmldoc.selectsinglenode("//configuration/add[@value='pc1']") strname = inputbox("enter hostname:", "hostname config", "hostname") colnode.attributes.getnameditem("value").text = strname xmldoc.save "c:\scripts\configuration.xml" change value of attribute "value" of nodes key value "kiosk_identifier":
dim strxpath, colnodes, strname, objnode strxpath = "//configuration/key[@value='kiosk_identifier']" set colnodes = xmldoc.documentelement.selectnodes(strxpath) strname = inputbox("enter hostname:", "hostname config", "hostname") each objnode in colnodes objnode.attributes.getnameditem("value").text = strname next xmldoc.save "c:\scripts\configuration.xml" p.s code below not tested
Comments
Post a Comment