From: anthony on
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
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
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
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