Solved

Creating config XML from VBScript

Posted on 2009-05-19
6
800 Views
Last Modified: 2013-11-25
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
Comment
Question by:hmsinfra
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Tompa99
ID: 24428888
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
 
LVL 1

Author Comment

by:hmsinfra
ID: 24432074
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
 
LVL 1

Author Comment

by:hmsinfra
ID: 24435047
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
 
LVL 1

Accepted Solution

by:
maytan80 earned 500 total points
ID: 24436590
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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now