Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS to update XML value with user input

Status
Not open for further replies.

deaconf19

IS-IT--Management
Jan 14, 2004
9
US
I have been reading a lot on here on how to do this and I am still confused on how to achieve this. I have no experience with XML and some VBS, but not the input box values.
I have an XML file that I need to modify the IP value with the user imputed value from a VBS input box and save it. Any direction or reading materials would be much appreciated.

Thanks

Code:
<!--
 * License
 *
 * The contents of this file are subject to the Jabber Commercial Software
 * License (the "License").  You may not copy or use this file, in either
 * source code or executable form, except in compliance with the License.
 * You may obtain a copy of the License by contacting Jabber.com, Inc. at
 * [URL unfurl="true"]http://www.jabber.com/.[/URL]
 *
 * Copyrights
 *
 * Portions created by or assigned to Jabber.com, Inc. are
 * Copyright (c) 2001, 2003-2006 Jabber.com, Inc.  All Rights Reserved.
-->
<cm:component xmlns:cm="[URL unfurl="true"]http://www.jabber.com/config/cm"[/URL] xmlns:config="[URL unfurl="true"]http://www.jabber.com/config"[/URL] config:description="Connection Manager" config:id="cm-1" config:runlevel="50" config:shutdown-timeout="240" config:version="4" xmlns="[URL unfurl="true"]http://www.jabber.com/config"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:schemaLocation="[URL unfurl="true"]http://www.jabber.com/config/cm[/URL]               ../schemas/xsd/config/cm/cm.xsd">
  <command xmlns="[URL unfurl="true"]http://www.jabber.com/config">[/URL]
    <max-restart-seconds>300</max-restart-seconds>
    <max-starts>-1</max-starts>
    <execute shell="/bin/sh">exec ../bin/cm -h %i -m %m -n %n -p %p -s %s</execute>
  </command>
  <service xmlns="[URL unfurl="true"]http://www.jabber.com/config">[/URL]
    <hosts/>
  </service>
  <cm:config xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm">[/URL]
    <max-sockets xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm">1000</max-sockets>[/URL]
    <thread-count xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm">3</thread-count>[/URL]
    <processors xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm">[/URL]
      <jsmcp:processor xmlns:jsmcp="[URL unfurl="true"]http://www.jabber.com/config/cm/jsmcp"[/URL] description="JSM Command Processor" id="cm-1_jsmcp-1" lib="jsmcp" load="jsmcp" xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/jsmcp"[/URL] xmlns:config="[URL unfurl="true"]http://www.jabber.com/config"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:schemaLocation="[URL unfurl="true"]http://www.jabber.com/config/cm/jsmcp[/URL] ../schemas/xsd/config/cm/jsmcp/jsmcp.xsd">
        <directors xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/jsmcp">[/URL]
          <xmppd:director xmlns:xmppd="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd"[/URL] id="cm-1_jsmcp-1_xmppd-1" lib="xmppd" load="xmppd" xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:schemaLocation="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd[/URL] ../schemas/xsd/config/cm/xmppd/xmppd.xsd">
            <external-channel xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd">[/URL]
              <host>192.168.150.10</host>
              <port>5222</port>
              <ssl:ssl xmlns:ssl="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl"[/URL] xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">[/URL]
                <ssl-mode xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">tls</ssl-mode>[/URL]
                <key xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">..\certs\host-key.pem</key>[/URL]
                <certificate xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">..\certs\host-key.pem</certificate>[/URL]
                <verify xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">0</verify>[/URL]
                <verify-depth xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">10</verify-depth>[/URL]
                <enable-weak-ciphers xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">false</enable-weak-ciphers>[/URL]
              </ssl:ssl>
            </external-channel>
            <x509-auth xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd">0</x509-auth>[/URL]
            <enable-jid-mapping xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd">0</enable-jid-mapping>[/URL]
            <compression-available xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd">0</compression-available>[/URL]
          </xmppd:director>
          <xmppd:director xmlns:xmppd="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd"[/URL] id="cm-1_jsmcp-1_xmppd-2" lib="xmppd" load="xmppd" xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:schemaLocation="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd[/URL] ../schemas/xsd/config/cm/xmppd/xmppd.xsd">
            <external-channel xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd">[/URL]
              <host>192.168.150.10</host>
              <port>5223</port>
              <ssl:ssl xmlns:ssl="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl"[/URL] xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">[/URL]
                <ssl-mode xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">listen</ssl-mode>[/URL]
                <key xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">..\certs\host-key.pem</key>[/URL]
                <certificate xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">..\certs\host-key.pem</certificate>[/URL]
                <verify xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">0</verify>[/URL]
                <verify-depth xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">10</verify-depth>[/URL]
                <enable-weak-ciphers xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/ssl">false</enable-weak-ciphers>[/URL]
              </ssl:ssl>
            </external-channel>
            <x509-auth xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd">0</x509-auth>[/URL]
            <enable-jid-mapping xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd">0</enable-jid-mapping>[/URL]
            <compression-available xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/xmppd">0</compression-available>[/URL]
          </xmppd:director>
        </directors>
        <config xmlns="[URL unfurl="true"]http://www.jabber.com/config/cm/jsmcp">[/URL]
          <connection type="connect">
            <host>[COLOR=red][b]192.168.150.10[/b][/color red]</host>
            <port>7400</port>
            <secret type="1">dGVzdA==</secret>
          </connection>
          <enable-broadcast>0</enable-broadcast>
          <hosts-to-track/>
        </config>
      </jsmcp:processor>
    </processors>
    <logging xmlns="[URL unfurl="true"]http://www.jabber.com/config/logging"/>[/URL]
  </cm:config>
</cm:component>
 
I found a VBS script to write create a new file with the changes I made to the VBS script. However that information is static in the VBS how do I invoke the VBS input box to make these changes instead of them being static and write the new xml file?

Code:
set oFSO = CreateObject("Scripting.FileSystemObject")

const ForReading = 1, ForWriting = 2, ForAppending = 8
'open the input file for reading
set oInFile = oFSO.OpenTextFile("cm-1.xml", ForReading)
'open the output file for writing
set oOutFile = oFSO.OpenTextFile("cm-1_output.xml", ForWriting, True)
'for each line in the input file

do while not oInFile.AtEndOfStream
  'read the line
  line = oInFile.ReadLine()
  line = process_line(line)
  oOutFile.WriteLine(line)
loop
'close the input file
oInFile.close
'close the outut file
oOutFile.close

[COLOR=red]
[b]
function process_line(line)
  set re = new regexp
  re.pattern = "<\s*port\s*>\s*5223\s*<\s*/port\s*>"
  if re.test(line) then
    process_line = "<port>6666</port>"
  else
    process_line = line
  end if
end function
[/b][/color]

the script is not mine I located on the web
 
Ideally, you would move the pattern and replace text outside the furction and pass them in.


Code:
'define the find regular expression and replace text
[red]
strFindRX = "whatever you want"
strReplace = inputBox("Replace " & strFindRX " with:")
[/red]

'for each line in the input file
do while not oInFile.AtEndOfStream
	'read the line
	line = oInFile.ReadLine()
	line = process_line(line[red], strFindRX, strReplace)[/red]
	oOutFile.WriteLine(line)
loop

...

function process_line(line[red], strFindRX, strReplace)[/red]
	set re = new regexp
	re.pattern = [red]strFindRX[/red]
	if re.test(line) then
	    process_line = [red]strReplace[/red]
	else
		process_line = line
	end if
end function

or

Code:
const ForReading = 1, ForWriting = 2, ForAppending = 8

set oInFile = oFSO.OpenTextFile("cm-1.xml", ForReading)
strXML = oInFile.ReadAll
oInFile.close

strFind = "whatever you want"
strReplace = inputBox("Replace " & strFindRX " with:")

strXML = replace(strXML, strFind, strReplace)

set oOutFile = oFSO.OpenTextFile("cm-1_output.xml", ForWriting, True)
oOutFile.write strXML
oOutFile.close

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thank you very much, I will give this a try.
 
I am getting an error Line 3 Char 46 error expected `)`

the line is this

strReplace = inputBox("Replace " & strFindRX " with:")


Am I supposed to input something there?
 
strReplace = inputBox("Replace " & strFindRX & " with:")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top