By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Using XML DOM to update machine.config

P: n/a
Hello all.
The following lines are an excerpt from a machine.config file:

<configuration>
<system.net>
<connectionManagement>
<add address="*" maxconnection="10"/>
</connectionManagement>
</system.net>

<system.web>
<processModel
enable="true"
timeout="Infinite"
idleTimeout="Infinite"
shutdownTimeout="0:00:05"
requestLimit="Infinite"
requestQueueLimit="5000"
restartQueueLimit="10"
memoryLimit="60"
webGarden="false"
cpuMask="0xffffffff"
userName="machine"
password="AutoGenerate"
logLevel="Errors"
clientConnectedCheck="0:00:05"
comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate"
responseDeadlockInterval="00:03:00"
maxWorkerThreads="100"
maxIoThreads="100"
minWorkerThreads="50"
/>
</system.web>
</configuration>

I'm using the following VBScript to edit the machine.config file and
change the "maxconnection" value from 10 to 48:

Dim strServer, XMLFilePath, XMLFileName, XMLFile, XMLFileBak
strServer = "000-WEB15-CRS"
XMLFilePath = "\\" & strServer & _
"\C$\Winnt\Microsoft.NET\Framework\v1.1.4322\CONFI G\"
XMLFileName = "machine.config"
XMLFile = XMLFilePath & XMLFileName
XMLFileBak = XMLFileName & "_Backup_" & ".txt"

Set xmlDoc = CreateObject("Msxml.DOMDocument")
xmlDoc.async = False
xmlDoc.PreserveWhitespace = True
xmlDoc.load XMLFile

'~~~ Create backup of original XML file
Set objFSO = CreateObject("Scripting.FileSystemObject")
CreateObject("Scripting.FilesystemObject") _
.GetFile(XMLFile).Name = XMLFileBak

Dim strNode, strKeyName, strNewValue
strNode = "/*/*/*/*[@address=" & Chr(34) & "*" & Chr(34) & "]"
strKeyName = "maxconnection"
strNewValue = "48"

Set objNode = xmlDoc.selectSingleNode (strNode)
objNode.setAttribute strKeyName, strNewValue
xmlDoc.Save XMLFile

Set xmlDoc = nothing
Set objFSO = nothing
Set objNode = nothing

The script works fine, except for one thing. The whitespace appears to
be preserved throughout the machine.config file - except for the
"<processModel" section. This section gets changed - the entire section
ends up on one horizontal line:

<processModel enable="true" timeout="Infinite"
idleTimeout="Infinite" shutdownTimeout="0:00:05"
requestLimit="Infinite" requestQueueLimit="5000" restartQueueLimit="10"
memoryLimit="60" webGarden="false" cpuMask="0xffffffff"
userName="machine" password="AutoGenerate" logLevel="Errors"
clientConnectedCheck="0:00:05" comAuthenticationLevel="Connect"
comImpersonationLevel="Impersonate" responseDeadlockInterval="00:03:00"
maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50"/>

Any idea what's causing this? Any help would be greatly appreciated.
Thanks!

- Dave

Dec 14 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Highlander, if you want your generated xml to be tidy,
then you are going to have to tidy it up yourself.

There are a number of "tidy-up-xml" mini-apps out there.
I wrote one myself in about an hour.

cheers, jw
__________________________________________________ __________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
Highlander wrote:
Any help would be greatly appreciated.
Thanks!

- Dave
Dec 14 '06 #2

P: n/a
Can't post to the Microsoft newsgroups, so this answer may not help
Highlander unless s/he is reading c.t.x...

Whitespace between XML attributes is not meaningful, and most XML tools
don't retain it or attempt to prettify it. You could try finding a
serializer which does so and plug that into your processing, or you
could write your own (warning: doing this right is nontrivial; you
should probably look at adapting one rather than trying to do it from
scratch), or you could postprocess the document to prettify the
attribute indentation -- or you could simply not worry about it, since
the change is harmless unless some other tool is badly broken.
Dec 14 '06 #3

P: n/a

mr_unreliable wrote:
Highlander, if you want your generated xml to be tidy,
then you are going to have to tidy it up yourself.

There are a number of "tidy-up-xml" mini-apps out there.
I wrote one myself in about an hour.

cheers, jw
__________________________________________________ __________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
Highlander wrote:
Any help would be greatly appreciated.
Thanks!

- Dave
jw - Can you post the code for the "tidy-up-xml" mini-app that you
wrote? Or point me in the direction of where I can find the other
mini-apps that are out there? Thanks!

- Dave

Dec 15 '06 #4

P: n/a
--- <snipper---
' retrieve the (untidy) xml from the dom...
Dim sXML ' as string
sXML = xmlDoc.xml
' MsgBox(sXML)

' ----------------------------------------------
' tidy up the result...
' ----------------------------------------------
Dim sTidyXML ' as string
' (first step) tidy the result...
sTidyXML = Replace(sXML, ">", ">" & vbCrLf)
' (second step)
sTidyXML = Replace(sTidyXML, "<", " <")
' MsgBox(sTidyXML)
' (third step) remove indent from rootnode tags...
sTidyXML = Replace(sTidyXML, " <?", "<?")
sTidyXML = Replace(sTidyXML, vbCrLf & vbCrLf, vbCrLf)
sTidyXML = Replace(sTidyXML, " <" & sRootNodeName, "<" &
sRootNodeName)
sTidyXML = Replace(sTidyXML, " </" & sRootNodeName, "</" &
sRootNodeName)
MsgBox(sTidyXML)

' sXMLTidySpec = GetLocalDirectory() & sXMLTidyFile ' for debugging
sXMLTidySpec = fso.GetSpecialFolder(tempFolder) & "\" & sXMLTidyFile
' construct the output file...
dbPrint sMe & "save xml tidy file: " & sXMLTidySpec

' write out the tidy file...
Dim oFile, oTextStream ' as object(s)
fso.CreateTextFile sXMLTidySpec, allowOverwrite ' creates the file
(no return)...
Set oXMLOutFile = fso.GetFile(sXMLTidySpec) ' "objectify" the file...

Set oTextStream = oXMLOutFile.OpenAsTextStream(ForWriting) ' ,
TristateUseDefault)
oTextStream.Write sTidyXML
oTextStream.Close

--- <end snippet---

Crude but effective, jw

Highlander wrote:
jw - Can you post the code for the "tidy-up-xml" mini-app that you
wrote? Or point me in the direction of where I can find the other
mini-apps that are out there? Thanks!

- Dave
Dec 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.