Howto save an edited xml doc w/MSXML

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?
0
anthony
8/19/2010 6:41:00 PM
scripting.vbscript 564 articles. 0 followers. Follow

3 Replies
986 Views

Similar Articles

[PageSpeed] 41

On Aug 19, 2:41=A0pm, anthony <anthonysvalen...@gmail.com> wrote:
> The following script modifies the content of my xml file:
> -------------------------------------------------------------------------=
--------------------------------------------------------------
> Dim nodeSel, nodeVal, index
>
> Dim name : name =3D "//ROOT/first_level/second_level/third_level"
> Dim xmlfile : xmlfile =3D "temp.xml"
> Dim value : value =3D "false"
> Dim xDoc
> Set xDoc =3D CreateObject( "MSXML.DOMDocument" )
> index =3D 0
>
> If xDoc.Load( xmlfile ) Then
> =A0 =A0 Set nodeSel =3D xDoc.selectSingleNode( name )
>
> =A0 =A0 'WScript.Echo "Found node", nodeSel.nodeName
>
> =A0 =A0 Set nodeVal =3D nodeSel.childNodes( index )
>
> =A0 =A0 WScript.Echo nodeVal.nodeValue
> =A0 =A0 nodeVal.nodeValue =3D value
> =A0 =A0 WScript.Echo nodeVal.nodeValue
> Else
> =A0 =A0WScript.Echo "XML document load failed"
> End If
> -------------------------------------------------------------------------=
--------------------------------------------------------------
>
> Here is the XML file:
> -------------------------------------------------------------------------=
--------------------------------------------------------------
> <?xml version=3D"1.0" encoding=3D"utf-8"?>
> <ROOT>
> =A0 =A0 <first_level>
> =A0 =A0 =A0 =A0 <second_level>
> =A0 =A0 =A0 =A0 =A0 =A0 <third_level>true</third_level>
> =A0 =A0 =A0 =A0 </second_level>
> =A0 =A0 </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
0
Tom
8/19/2010 7:35:40 PM
On Aug 19, 3:35=A0pm, Tom Lavedas <tglba...@verizon.net> wrote:
> On Aug 19, 2:41=A0pm, anthony <anthonysvalen...@gmail.com> wrote:
>
>
>
> > The following script modifies the content of my xml file:
> > -----------------------------------------------------------------------=
----------------------------------------------------------------
> > Dim nodeSel, nodeVal, index
>
> > Dim name : name =3D "//ROOT/first_level/second_level/third_level"
> > Dim xmlfile : xmlfile =3D "temp.xml"
> > Dim value : value =3D "false"
> > Dim xDoc
> > Set xDoc =3D CreateObject( "MSXML.DOMDocument" )
> > index =3D 0
>
> > If xDoc.Load( xmlfile ) Then
> > =A0 =A0 Set nodeSel =3D xDoc.selectSingleNode( name )
>
> > =A0 =A0 'WScript.Echo "Found node", nodeSel.nodeName
>
> > =A0 =A0 Set nodeVal =3D nodeSel.childNodes( index )
>
> > =A0 =A0 WScript.Echo nodeVal.nodeValue
> > =A0 =A0 nodeVal.nodeValue =3D value
> > =A0 =A0 WScript.Echo nodeVal.nodeValue
> > Else
> > =A0 =A0WScript.Echo "XML document load failed"
> > End If
> > -----------------------------------------------------------------------=
----------------------------------------------------------------
>
> > Here is the XML file:
> > -----------------------------------------------------------------------=
----------------------------------------------------------------
> > <?xml version=3D"1.0" encoding=3D"utf-8"?>
> > <ROOT>
> > =A0 =A0 <first_level>
> > =A0 =A0 =A0 =A0 <second_level>
> > =A0 =A0 =A0 =A0 =A0 =A0 <third_level>true</third_level>
> > =A0 =A0 =A0 =A0 </second_level>
> > =A0 =A0 </first_level>
> > </ROOT>
> > -----------------------------------------------------------------------=
----------------------------------------------------------------
>
> > How can I save the xml file with the modified value?
>
> Have your tried "xDoc.Save xmlfile"? =A0or xDoc.Save "newversion.xml"
> _____________________
> Tom Lavedas

Yes, I just did.  Works perfectly!  Thanks for closing this thread.
0
anthony
8/19/2010 7:50:48 PM
On Aug 19, 3:50=A0pm, anthony <anthonysvalen...@gmail.com> wrote:
> On Aug 19, 3:35=A0pm, Tom Lavedas <tglba...@verizon.net> wrote:
>
>
>
> > On Aug 19, 2:41=A0pm, anthony <anthonysvalen...@gmail.com> wrote:
>
> > > The following script modifies the content of my xml file:
> > > ---------------------------------------------------------------------=
------------------------------------------------------------------
> > > Dim nodeSel, nodeVal, index
>
> > > Dim name : name =3D "//ROOT/first_level/second_level/third_level"
> > > Dim xmlfile : xmlfile =3D "temp.xml"
> > > Dim value : value =3D "false"
> > > Dim xDoc
> > > Set xDoc =3D CreateObject( "MSXML.DOMDocument" )
> > > index =3D 0
>
> > > If xDoc.Load( xmlfile ) Then
> > > =A0 =A0 Set nodeSel =3D xDoc.selectSingleNode( name )
>
> > > =A0 =A0 'WScript.Echo "Found node", nodeSel.nodeName
>
> > > =A0 =A0 Set nodeVal =3D nodeSel.childNodes( index )
>
> > > =A0 =A0 WScript.Echo nodeVal.nodeValue
> > > =A0 =A0 nodeVal.nodeValue =3D value
> > > =A0 =A0 WScript.Echo nodeVal.nodeValue
> > > Else
> > > =A0 =A0WScript.Echo "XML document load failed"
> > > End If
> > > ---------------------------------------------------------------------=
------------------------------------------------------------------
>
> > > Here is the XML file:
> > > ---------------------------------------------------------------------=
------------------------------------------------------------------
> > > <?xml version=3D"1.0" encoding=3D"utf-8"?>
> > > <ROOT>
> > > =A0 =A0 <first_level>
> > > =A0 =A0 =A0 =A0 <second_level>
> > > =A0 =A0 =A0 =A0 =A0 =A0 <third_level>true</third_level>
> > > =A0 =A0 =A0 =A0 </second_level>
> > > =A0 =A0 </first_level>
> > > </ROOT>
> > > ---------------------------------------------------------------------=
------------------------------------------------------------------
>
> > > How can I save the xml file with the modified value?
>
> > Have your tried "xDoc.Save xmlfile"? =A0or xDoc.Save "newversion.xml"
> > _____________________
> > Tom Lavedas
>
> Yes, I just did. =A0Works perfectly! =A0Thanks 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
0
Tom
8/20/2010 12:46:59 PM
Reply:

Similar Artilces:

Editing Dates
When I enter March 2010 into excel it automatically changes it to Mar-10. I'd like it to stay the way I originally typed it in. I already tried unchecking the autocomplete in the advanced options but it didn't work. Two options: 1. Precede your entry with an apostrophe (') 2. Format your cells as text before you enter data. Regards, Fred "laceylee1027" <laceylee1027@discussions.microsoft.com> wrote in message news:55D904A4-FA49-425F-9837-D1104229E750@microsoft.com... > When I enter March 2010 into excel it automatically changes it to Mar-10. &...

Save operation on table 'MOP_item_MSTR' failed accessing SQL data
I am getting this message randomly, when clicking the Schedule MO button on Manufacturing Order entry window. Dynamics GP, version 10 after the above message, I get: A save operation on table 'MOP_item_MSTR' has reached the end of the table. any suggestions? I cant find anything on these in knowledgebase. thanks! -- Doug ...

Outlook 2002 not saving passwords #2
I've tried the suggested fix at (the reg edit Protected Storage System Provider) and couldn't find the switches and settings mentioned (there wasn't a section for windows xp so I just went by the windows 2000) The following solution should work for all Outlook versions on Windows XP (note, this article is written for OE but the solution applies to Outlook as well. Just ignore the parts that refer to OE): http://support.microsoft.com/default.aspx?scid=kb;en-us;264672 -- Jocelyn Fiorello MVP - Outlook *** Messages sent to my e-mail address will NOT be answered -- please reply...

Please need help w/Form Code
I have a parameter form when I enter the data it puts the data in the first record it finds. How can I revise this to find the record I select and save the data to the specific records? Thank you in advance for any help you can provide. Private Sub cboMbr_AfterUpdate() Dim rst As DAO.Recordset Set rst = Me.RecordsetClone rst.FindFirst "[ID] = '" & cboMb & "'" If Not rst.NoMatch Then Me.Bookmark = rst.Bookmark End If End Sub Are the controls that you enter data into bound or unbound? -- Steve S -------------------------...

Excel with an embedded Word Doc
I have a workbook that has an embedded word document on one of the worksheets. This worksheet can be visible or invisible. I have a print macro that prints out all necessary worksheets, it then checks to see if this worksheet with the embedded doc is visible, and if so, it launches the document. What i need the macro to do then is to print the document and close the application. Can anyone help with this? Cheers Scream -- Scream ...

How copy multiple pages in publisher doc to new doc
want to copy some selected pages from a multi-page Publisher document into a new publisher document. I can of course copy and paste them one by one, but is there a simpler way? Office Help talks of selecting pages in thumbnail pane, but I can't find out how to activate and access a thumbnail pane of a publisher doc. Edit, open Office Clipboard, copy the pages. Depending on your setup, you should be able to collect 24 items. The text will not come over if the text boxes are linked. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft...

Prefered event to trap in cell editing?
Worksheet_Change(ByVal Target As Range) Worksheet_SelectionChange(ByVal Target As Range) I want to trigger code if a single cell changes, which is the best event? I would also like to read more on these or similar sheet events but really don't know where to look. The supplied help file is slim on these topics. If the cell gets user entries, choose Worksheet_Change. If the cell contains a formula, use Worksheet_Calculate. One ref: http://cpearson.com/excel/events.htm In article <4_ednREVIP33O9bcRVn-vg@comcast.com>, ";-\)" <james.holland@comcast.net> w...

Outlook 2007 not saving email passwords
Windows XP This issue has been dealt with using all the "known" methods to no avail. Outlook has been removed and reinstalled. Before reinstalling it, Outlook Express was set up and IT keeps the passwords fine. After reinstalling it, the same issue remains. Immediately after typing in the account information, clicking on the Test Account Settings brings up the dialog asking for the password as if it had never been typed in at all. Any good suggestions? Thanks, Fred "Fred Marshall" <fmarshallx@remove_the_x.acm.org> wrote in message news:e$mDQ3jkJHA.500@TK2MS...

What are the differences between MSXML and .NET XML Parsers?
Any kind of differences? Were they buid on the common base or different? -- WBR, Michael Nemtsev :: blog: http://spaces.msn.com/laflour "At times one remains faithful to a cause only because its opponents do not cease to be insipid." (c) Friedrich Nietzsche Michael Nemtsev wrote: > Any kind of differences? > Were they buid on the common base or different? MSXML supports SAX parsing and supports building a DOM document (mostly compliant with W3C DOM Level 1 XML and lots of Microsoft extensions). ..NET parsers don't support SAX, rather .NET with XmlReader/XmlT...

Web-publishing an Access form w/ vba code
My apologies if this issue has been addressed previously, but I have not been able to find a straightforward solution (assuming there is one). I am looking for advice on the best way for me to publish a form I have created in Access 2000 to the web. I used the TSI Form-to- DAP wizard to create a DAP that mirrors the form, but I need help making the code behind the submit button work. The code uses the input in the form's textboxes to query multiple tables and existing queries in the database. It then performs several calculations and updates the records with the calculated values. It ...

Bulk save and import in Outlook 2000
Is there a program that would allow me to import an entire folder of icalander and/or vcard files into Outlook 2000 instead of having to do one at a time? Also, is there one that would allow me to SAVE an entire folder of the same from within Outlook? Thanks ...

Save Excel 2002 to be read by MacIntosh Excel 2004?
Is it possible for the MacIntosh Excel 2004 to read an Excel XP 2002 spreadsheet? How should XP spreadsheet be saved? HELP, please!! MacXL98/01/v.X/2004 files are the exact same format as WinXL97/00/02/03 files. Save the file as an XL workbook and transfer it to the Mac. In article <0D5EBD4E-E12F-4E2D-AC2C-F45E556284E9@microsoft.com>, "cagedbirdflies" <cagedbirdflies@discussions.microsoft.com> wrote: > Is it possible for the MacIntosh Excel 2004 to read an Excel XP 2002 > spreadsheet? How should XP spreadsheet be saved? HELP, please!! "JE McGimpse...

Edit Boxes for passwords?
I've just started learning some of this Windows MFC stuff and have been experimenting with simple dialog-only programs. I wanted to try to have an edit box that would initialize to say "Enter password here" and then clear on the first change event and then display asterisks as a password is entered. This is not as easy as I had hoped. Is there any way to simply change the edit box style to password mode? I am not having much luck replacing characters with *'s as they are typed because this screws up the cursor position. Is there a simple solution for a beginner? Thanks. The ...

Settings in Outlook 2003 are not saved
In our domain there is a user who's settings in outlook are not saved. Every time the user is logged in the email account is gone and has te be made new. The user is a member of domainusers and has all rights to the profile. Owner of the profile is administrator. The profile is kept on the server, not local. Any suggestions why this is . All other users withe the same type of account are working properly. Greetings Are you using an Exchange Server with mailboxes or are the emails stored on a personal folder .pst file? Also, are you stating the profile has to be re-created or the actu...

F12 does not bring up Save As in Word 2003
When I hit F12 in word, a box pops up saying no fuction assigned to this button. When I tried to go under the Tools menu, then Customize, there is a Keyboard button. In there, there's a reset button to restore them all to defaults, but it is grayed out like I'm already set to the defaults. Does that mean something else is overriding my Function keys and Word is ok? Seems easier and more efficient to make a toolbar button to do Save As. TOOLS>CUSTOMIZE>Command Tab, and scroll down the File selectins to Save As. Hold the ALT Key and drag Save As to the location on...

XML Transform
I have a Visual basic application. I need to convert this application to a web form asp.net. In this application there are checkboxes to print diffent forms. so for example if user checks on on individualperson forms than individualPerson forms will be printed out directly to the printer. Some of the fields of the individualPerson forms are coming from database so for example name : John Smith This is to certify name : <database field> At the bottom there will be address of John Smith and so on VB application is using mail merge to print out these forms directl...

Imbed an HTML doc in the body of an e-mail
For years I have received wonderful looking e-mails from vendors, advertisers, etc. who imbed an HTML doc into the body of their e-mail, so when I open the e-mail I am presented with a colorful, interactive document, yet I have NEVER been able to figure out how in the world they're doing it. Every time I try and insert an HTML document it simply goes as an attachment, NOT as the body of the document. I have specific customers I'd like to reach with attractive, interactive documents but I can't seem to figure out how. I'm using XP Pro '03. Can anybody help? Thanks, BW...

embed .wav to word doc
how can you embed a .wav into a word doc such that it plays when the doc is opened? ...

Saving publisher pages as JPEG files
I need to save publisher pages as a high resolution JPEG, at least 300 DPI, HOW! -- Doughboy In 2003; File | Save As ... then scroll down to ext you want. I don't think earlier versions had this option. "doughboy" <doughboy@discussions.microsoft.com> wrote in message news:65E1F456-3D9F-495F-B4E2-718E777B818F@microsoft.com... |I need to save publisher pages as a high resolution JPEG, at least 300 DPI, | HOW! | -- | Doughboy Rob Giordano (Crash) wrote: > In 2003; File | Save As ... then scroll down to ext you want. I don't > think earlier versions had this...

Create XML Doc from XML returned by URL
Hi, I am using a 3rd party product that returns XML when calling its exe through a URL. For instance, the following URL calls this exe in Internet Explorer and returns valid, well formed XML and displays it in the browser: http://server/app/livelink.exe? func=search&where1=report&outputformat=xml My goal: I want to send this http request in VB.NET code, in ASP.NET and store the XML that is returned in an XML document. So, my general question is: How can I store the XML returned by an http request, in an XML Document? Thanks in Advance, BLH You can store it in an xml doc...

Unable to D/L messages w/ corrupt headers
Recently I have been receiving emails to my POP3 server that will not download using Outlook 2002, most likely because the email messages or headers do not conform to required standards or are otherwise corrupted. To remedy the problem, I telnet into my pop3 server and delete the corrupt message, or, more recently, I discovered a web site (mail2web) where I can access my email through the web. Is there any way that I can correct the problem with Outlook 2002, so that I do not have to use telnet or mail2web to access my server and delete the corrupt message? Thanks This is one of the cor...

Help! I cant write or edit anything
Please i really need someone to help me asap. i've been using microsoft word all night, but suddenly when i add a picture (i've added at least 6 other ones from My Pictures over the evening) but suddenly i cant edit anything in my document, not even copy or paste im using microsoft office 2007 Hi Rachael, This most often occurs if Word 2007 is running when a Vista computer is restarted to complete the installation of an automatic update for Word 2007. In this case the problems are caused by corruption of the Word Data registry subkey, and they can easily be fixed by going to ...

Problems w/ Exchange 5.5 MTA
I am having some problems with my Exchange 5.5 MTA. Here is the configuration. Antivirus is configured correctly. Exchange 5.5 SP4 Windows 2000 SP4 This server is a bridgehead with Directory Replication Connectors, Site Connectors and an Internet Mail Connectors. Recently, users have been complaining about mail not going to their intended recipients. I created some test accounts on various servers and noticed that some mail made it, some did not. When I track the messages, they typically get received by the MTA but do not get forwarded on to a connector or another MTA. They just disapear...

Individual formatting on a text box on a report w/tabular layou?
Hyall, I can change the background color of the detail in a report with tabular layout (that is, similar to a continuous form) using Detail_Format: Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) With Me Select Case .txtCondition Case "Green" .Section("Detail").BackColor = vbWhite Case "Yellow" .Section("Detail").BackColor = vbYellow Case "Red" .Section("Detail").BackColor = vbRed End Select End With End Su...

Removing Near-Duplicate Rows, Leaving Those w/Most Data in Specific Columns
I have a spreadsheet with about 20,000 rows of data and I am trying to eliminate unnecessary rows. Columns B&C contain numbers, and columns D through AR contain text. Many rows contain identical information in columns B, C, D, E, & F, but the information in the remaining columns may differ. I would like to eliminate rows with duplicate data in columns B through F, retaining the rows with the greatest number of entries in columns G through AR. An example of what I would like to get to is shown below. BEFORE B C D E F G H I J K L Row 1 12 34 DD EE F...