• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 878
  • Last Modified:

Creating config XML from VBScript

Hello,

I'm trying to create a vbscript that allows me to automate some deployments to our various environments. Each environment usually has the same config files. however they have different parameters for things like sql connection strings etc. I want to have a vbscript that is able to write like a web.config file with the paramters I choose. I couldn't find anything opensoruce for this. Anyone that is familiar with vbscript able to help? Attached is a beginning sample of a web.config file that I would want to generate using a vbscript. The endpoint address is what I would want to have as a variable as it varies in the different environments. :


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 
	<configSections>
		<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging" />
	</configSections>
	
	<system.diagnostics>
  <sources>
   <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
    <listeners>
     <add type="System.Diagnostics.DefaultTraceListener" name="Default">
      <filter type="" />
     </add>
    </listeners>
   </source>
   <source name="System.ServiceModel" switchValue="Warning, ActivityTracing"
    propagateActivity="true">
    <listeners>
     <add type="System.Diagnostics.DefaultTraceListener" name="Default">
      <filter type="" />
     </add>
    </listeners>
   </source>
  </sources>
 </system.diagnostics>
 <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
		<listeners>
			<add source="Enterprise Library Logging" formatter="Text Formatter"
     log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
     traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
     name="Formatted EventLog TraceListener" />
		</listeners>
		<formatters>
			<add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
     type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging"
     name="Text Formatter" />
		</formatters>
		
		<logFilters>
			<add minimumPriority="0" maximumPriority="2147483647" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.PriorityFilter, Microsoft.Practices.EnterpriseLibrary.Logging" name="Priority Filter" />
		</logFilters>
 
		<categorySources>
			<add switchValue="All" name="AdServer">
				<listeners>
					<add name="Formatted EventLog TraceListener" />
				</listeners>
			</add>
		</categorySources>
 
		<specialSources>
			<allEvents switchValue="All" name="All Events" />
			<notProcessed switchValue="All" name="Unprocessed Category" />
			<errors switchValue="All" name="Logging Errors &amp; Warnings">
				<listeners>
					<add name="Formatted EventLog TraceListener" />
				</listeners>
			</errors>
		</specialSources>
	</loggingConfiguration>
 
	<system.serviceModel>
		<bindings>
   <netTcpBinding>
    <binding name="ORMBinding" receiveTimeout="00:00:00.2000000"
     maxConnections="1000">
     <readerQuotas maxStringContentLength="16384" />
    </binding>
   </netTcpBinding>
  </bindings>
		<diagnostics>
			<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
		</diagnostics>
		<client>
			<endpoint address="net.tcp://192.168.1.106:5151/Server"
    binding="netTcpBinding" bindingConfiguration="ORMBinding" contract="abc.Frontend.Common.ICommunicationHandler"
    name="ORMServer" />
		</client>
	</system.serviceModel>

Open in new window

0
hmsinfra
Asked:
hmsinfra
  • 2
1 Solution
 
Tompa99Commented:
Hi,

We are using T4 to solve the same problem that you have with multiple environments with just connection string and endpoint that is diffrent in our config files.

http://www.olegsych.com/2007/12/how-to-use-t4-to-generate-config-files/
and
http://www.olegsych.com/2007/12/text-template-transformation-toolkit/

When you have it in place it works great for us.

Best Regrds Tompa

0
 
hmsinfraAuthor Commented:
Hey,

That took would work for another project, but for this I don't think it will work. Sometimes under heavy load we may need to take a PERF server and move it to PROD, and sometimes the PROD servers may have like different endpoint addresses. Is there a way to use something like VBScript to edit the XML file and replace lines like the attached code?

        <diagnostics>
            <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
        </diagnostics>
        <client>
            <endpoint address="net.tcp://111.111.111.111:5050/Server"
    binding="netTcpBinding" bindingConfiguration="OMBinding" contract="abc.Frontend.Common.ICommunicationHandler"
    name="ORServer" />
        </client>
    </system.serviceModel>
 
 
replace the endpoint address= with
 
 <endpoint address="net.tcp://999.999.999.999:5050/Server"
    binding="netTcpBinding" bindingConfiguration="OMBinding" contract="abc.Frontend.Common.ICommunicationHandler"
    name="ORServer" />
 
 
See only the IP address changed?

Open in new window

0
 
hmsinfraAuthor Commented:
Also I found this page

http://www.devguru.com/technologies/xml_dom/15891.asp

Which makes it seem like its easy to simply add an attibute/replace. I however can't seem to get it working. Can anyone test and give me an example on how to replace the attributes?

Thanks!
0
 
maytan80Commented:
You want this page...

http://www.devguru.com/technologies/xml_dom/15603.asp

Copy paste the following code to a vbs file, and save the vbs in the same folder as the webconfig.xml file. Comment out the MsgBox lines when you are sure the code works as planned.

setAddrValue = "net.tcp://192.168.1.106:5151/Server1"

set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("Webconfig.xml")

'Find the endpoint element
Set NodeList = objXMLDoc.getElementsByTagName("endpoint")
For Each Elem In NodeList
   MsgBox(Elem.tagName)
   Set elemAttr = Elem.Attributes
   For each attr in elemAttr
    MsgBox(attr.Name)
    MsgBox(attr.Value)

'Iterate till we find the address element
    If attr.Name = "address" Then
       attr.Value = setAddrValue
       MsgBox(attr.Value)
        objXMLDoc.Save("Webconfig.xml")      
    End If
  Next
Next
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now