Prev: Capturing STDOUT data when exec cmd hangs
Next: Rename files in directory with certain extension?
From: anthony on 19 Aug 2010 14:41 The following script modifies the content of my xml file: --------------------------------------------------------------------------------------------------------------------------------------- Dim nodeSel, nodeVal, index Dim name : name = "//ROOT/first_level/second_level/third_level" Dim xmlfile : xmlfile = "temp.xml" Dim value : value = "false" Dim xDoc Set xDoc = CreateObject( "MSXML.DOMDocument" ) index = 0 If xDoc.Load( xmlfile ) Then Set nodeSel = xDoc.selectSingleNode( name ) 'WScript.Echo "Found node", nodeSel.nodeName Set nodeVal = nodeSel.childNodes( index ) WScript.Echo nodeVal.nodeValue nodeVal.nodeValue = value WScript.Echo nodeVal.nodeValue Else WScript.Echo "XML document load failed" End If --------------------------------------------------------------------------------------------------------------------------------------- Here is the XML file: --------------------------------------------------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <ROOT> <first_level> <second_level> <third_level>true</third_level> </second_level> </first_level> </ROOT> --------------------------------------------------------------------------------------------------------------------------------------- How can I save the xml file with the modified value?
From: Tom Lavedas on 19 Aug 2010 15:35 On Aug 19, 2:41 pm, anthony <anthonysvalen...(a)gmail.com> wrote: > The following script modifies the content of my xml file: > --------------------------------------------------------------------------------------------------------------------------------------- > Dim nodeSel, nodeVal, index > > Dim name : name = "//ROOT/first_level/second_level/third_level" > Dim xmlfile : xmlfile = "temp.xml" > Dim value : value = "false" > Dim xDoc > Set xDoc = CreateObject( "MSXML.DOMDocument" ) > index = 0 > > If xDoc.Load( xmlfile ) Then > Set nodeSel = xDoc.selectSingleNode( name ) > > 'WScript.Echo "Found node", nodeSel.nodeName > > Set nodeVal = nodeSel.childNodes( index ) > > WScript.Echo nodeVal.nodeValue > nodeVal.nodeValue = value > WScript.Echo nodeVal.nodeValue > Else > WScript.Echo "XML document load failed" > End If > --------------------------------------------------------------------------------------------------------------------------------------- > > Here is the XML file: > --------------------------------------------------------------------------------------------------------------------------------------- > <?xml version="1.0" encoding="utf-8"?> > <ROOT> > <first_level> > <second_level> > <third_level>true</third_level> > </second_level> > </first_level> > </ROOT> > --------------------------------------------------------------------------------------------------------------------------------------- > > How can I save the xml file with the modified value? Have your tried "xDoc.Save xmlfile"? or xDoc.Save "newversion.xml" _____________________ Tom Lavedas
From: anthony on 19 Aug 2010 15:50 On Aug 19, 3:35 pm, Tom Lavedas <tglba...(a)verizon.net> wrote: > On Aug 19, 2:41 pm, anthony <anthonysvalen...(a)gmail.com> wrote: > > > > > The following script modifies the content of my xml file: > > --------------------------------------------------------------------------------------------------------------------------------------- > > Dim nodeSel, nodeVal, index > > > Dim name : name = "//ROOT/first_level/second_level/third_level" > > Dim xmlfile : xmlfile = "temp.xml" > > Dim value : value = "false" > > Dim xDoc > > Set xDoc = CreateObject( "MSXML.DOMDocument" ) > > index = 0 > > > If xDoc.Load( xmlfile ) Then > > Set nodeSel = xDoc.selectSingleNode( name ) > > > 'WScript.Echo "Found node", nodeSel.nodeName > > > Set nodeVal = nodeSel.childNodes( index ) > > > WScript.Echo nodeVal.nodeValue > > nodeVal.nodeValue = value > > WScript.Echo nodeVal.nodeValue > > Else > > WScript.Echo "XML document load failed" > > End If > > --------------------------------------------------------------------------------------------------------------------------------------- > > > Here is the XML file: > > --------------------------------------------------------------------------------------------------------------------------------------- > > <?xml version="1.0" encoding="utf-8"?> > > <ROOT> > > <first_level> > > <second_level> > > <third_level>true</third_level> > > </second_level> > > </first_level> > > </ROOT> > > --------------------------------------------------------------------------------------------------------------------------------------- > > > How can I save the xml file with the modified value? > > Have your tried "xDoc.Save xmlfile"? or xDoc.Save "newversion.xml" > _____________________ > Tom Lavedas Yes, I just did. Works perfectly! Thanks for closing this thread.
From: Tom Lavedas on 20 Aug 2010 08:46 On Aug 19, 3:50 pm, anthony <anthonysvalen...(a)gmail.com> wrote: > On Aug 19, 3:35 pm, Tom Lavedas <tglba...(a)verizon.net> wrote: > > > > > On Aug 19, 2:41 pm, anthony <anthonysvalen...(a)gmail.com> wrote: > > > > The following script modifies the content of my xml file: > > > --------------------------------------------------------------------------------------------------------------------------------------- > > > Dim nodeSel, nodeVal, index > > > > Dim name : name = "//ROOT/first_level/second_level/third_level" > > > Dim xmlfile : xmlfile = "temp.xml" > > > Dim value : value = "false" > > > Dim xDoc > > > Set xDoc = CreateObject( "MSXML.DOMDocument" ) > > > index = 0 > > > > If xDoc.Load( xmlfile ) Then > > > Set nodeSel = xDoc.selectSingleNode( name ) > > > > 'WScript.Echo "Found node", nodeSel.nodeName > > > > Set nodeVal = nodeSel.childNodes( index ) > > > > WScript.Echo nodeVal.nodeValue > > > nodeVal.nodeValue = value > > > WScript.Echo nodeVal.nodeValue > > > Else > > > WScript.Echo "XML document load failed" > > > End If > > > --------------------------------------------------------------------------------------------------------------------------------------- > > > > Here is the XML file: > > > --------------------------------------------------------------------------------------------------------------------------------------- > > > <?xml version="1.0" encoding="utf-8"?> > > > <ROOT> > > > <first_level> > > > <second_level> > > > <third_level>true</third_level> > > > </second_level> > > > </first_level> > > > </ROOT> > > > --------------------------------------------------------------------------------------------------------------------------------------- > > > > How can I save the xml file with the modified value? > > > Have your tried "xDoc.Save xmlfile"? or xDoc.Save "newversion.xml" > > _____________________ > > Tom Lavedas > > Yes, I just did. Works perfectly! Thanks for closing this thread. Glad I could help. Next time you're faced with such a dilemma, try doing what I did to confirm my suspicion that Save was the method you wanted: Open an MS Office application (assuming you have one loaded), access its Macro (VBA) IDE (in the Tools menu or usually the Alt-F11 key), access its Object viewer, find the object's reference, and then use the viewer to figure out what command it is that you want. Finding the right reference library (.dll, ocx, .tbl, .exe file) sometimes requires a search through the Class definitions in the registry, but it's usually as simple as right-clicking in the "Members" pane of the object viewer and searching through the list of available objects in the References dialog window. That's how I found the MSXML object, in this case. If you don't have MS Office, search the internet for an object viewer. There are many out there and some are free. _____________________ Tom Lavedas
|
Pages: 1 Prev: Capturing STDOUT data when exec cmd hangs Next: Rename files in directory with certain extension? |