Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Editing a XML file with vbs

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,52254
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Editing a XML file with vbs
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Editing a XML file with vbs - 9/27/2007 1:06:15 AM   
  Help

 

Posts: 5
Score: 0
Joined: 9/27/2007
Status: offline
 
I would like to know how to edit a line like whats listed below. I have no problem with objXMLDoc.createElement and objXMLDoc.createTextNode but I have been unsuccessful with editing entry key values using vbs. An example would be great.

- <node name="AcrobatReader">

- <map>

  <entry key="Version" value="8.0" />
  <entry key="Path" value="C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe" />   </map>
 
 
Post #: 1
 
 RE: Editing a XML file with vbs - 9/27/2007 3:16:59 AM   
  dm_4ever


Posts: 2723
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Do you know how to read the specific value you're trying to change? If so, rather than echo it out to the screen...have it equal your new value and then save the xml file.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Help)
 
 
Post #: 2
 
 RE: Editing a XML file with vbs - 9/28/2007 1:51:14 AM   
  Help

 

Posts: 5
Score: 0
Joined: 9/27/2007
Status: offline
The issue I'm having is that I can't figure out how to write the code to change <entry key="Version" value="8.0" /> to a new value. When I use entry key in my code it give me the error listed below.
 
C:\Test\XML.vbs(8, 1) msxml3.dll: This name may not contain the ' ' character:

entry--> <--key


Exit code: 0 , 0000h

(in reply to Help)
 
 
Post #: 3
 
 RE: Editing a XML file with vbs - 9/28/2007 1:56:45 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
Let us see the code please.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Help)
 
 
Post #: 4
 
 RE: Editing a XML file with vbs - 9/28/2007 4:48:02 AM   
  Help

 

Posts: 5
Score: 0
Joined: 9/27/2007
Status: offline
Dim XmlFileName: XmlFileName = "c:\test\DefaultApplicationProperties.xml" 
Dim XPath: Xpath = "/System/Check/DocumentViewer/AcrobatReader/map"
Dim sAttribName: sAttribName = "Version"
Dim sAttribValue: sAttribValue = "8.0"
Dim sElemText: sElemText = "7.0" '
Dim xmlDoc: set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.setProperty "SelectionLanguage", "XPath"
Result = xmlDoc.load(XmlFileName)
If Not Result Then
Msgbox("Error loading file """ & XmlFileName & """")
Else
Dim node: set node = xmlDoc.selectSingleNode(XPath)
If Not node is Nothing Then
     
 node.setAttribute sAttribName, sAttribValue
 node.text = sElemText
End If
xmlDoc.Save XmlFileName
End If

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Editing a XML file with vbs - 9/28/2007 5:03:59 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
This code does not do what you say you are trying to do. For one thing the XPath query would not return an entry node at all. Secondly, you say:

"When I use entry key in my code it give me the error listed below."

but the code that you posted does not mention Entry at all.

Please post the actual code that you are running along with a snippet of the XML file that shows the structure from the root node down to the node that you are trying to change.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Help)
 
 
Post #: 6
 
 RE: Editing a XML file with vbs - 9/28/2007 5:40:20 AM   
  Help

 

Posts: 5
Score: 0
Joined: 9/27/2007
Status: offline
Yea I actually change the code because Entry Key kept throughing up errors  so I thought I would use Xpath. As I explained before I'm not well versed in XML as it pertains to vbs.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">
<preferences>
<root type="system">
 <map/>
 <node name="Check">
  <map/>
  <node name="DocumentViewer">
   
   <node name="AcrobatReader">
    <map>
     <entry key="Version" value="8.0"/>  <--------------------------------------------------------------------Value I want to change.
     <entry key="Path" value="C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"/>
    </map>

-

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Editing a XML file with vbs - 9/28/2007 5:42:22 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
Ok, so there is the XML. Now could you please post the actual code that you are running and explain precisely what the problem is with the code that you post?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Help)
 
 
Post #: 8
 
 RE: Editing a XML file with vbs - 9/28/2007 6:37:27 AM   
  ehvbs

 

Posts: 2223
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Help,

this code shows how to access xml attributes:


      

use the XML / XPath Docs to see why it works like this.

Good luck!

ehvbs

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: Editing a XML file with vbs - 9/28/2007 6:55:39 AM   
  Help

 

Posts: 5
Score: 0
Joined: 9/27/2007
Status: offline
Thanks ehvbs this looks like what I was looking for.

(in reply to Help)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Editing a XML file with vbs Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts